The standard example for everyone to share the python generated random password implementation process for your reference, the specific content as follows
Wrote a program, mainly used to detect the MySQL database empty password and weak password,
Here, three types of weak passwords are defined:
1. Continuous numbers , such as 123456, are implemented in Get_weak_num
2. Continuous letters , such as ABCDEF, are implemented in Get_weak_character
Of course, the numbers are random.
3. Random combination of numbers and letters . Implemented in Get_weak_num_character.
A list of password_exist is also defined to hold different passwords. If the newly generated password exists in the list, the connection to the MySQL database is not made directly to the next loop.
Specific as follows:
#coding =utf8import random,string,mysqldbdef get_num (): Return Random.randint (0,9) def Get_char (): Return Random.choice (Tuple (string.lowercase)) def choose_any (): Return [Str (Get_num ()), Get_char ()]def get_weak_num (): weak_num=[] Initial _num=get_num () for I in Range (Get_num ()): Weak_num.append (str (initial_num+i)) if Initial_num +i ==9:break; return Weak_numdef Get_weak_character (): weak_character=[] Initial_character=get_char () for I in Range (Get_num ()): W Eak_character.append (Chr (initial_character) +i)) if Chr (Ord (initial_character) +i) = = ' Z ': Break return Weak_ch Aracterdef Get_weak_num_character (): Return [Random.choice (Choose_any ()) for Num in range (Get_num ())]password_exist=[ ]for I in range (10000): choice = [Get_weak_num (), Get_weak_character (), Get_weak_num_character ()] password= ". Join (Rand Om.choice (choice)) print "First" +str (i) + "Times password:" +password if password in password_exist:continue Else:try:MySQ Ldb.connect (' 192.168.244.145 ', ' root', password) print ' The password for MySQL are: ' +password break except:continue password_exist.append (password) If i = = 9999:print ' The password is not so weak~ '
The above is the whole content of this article, I hope that everyone's study has helped.