How Python generates random passwords

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.