<Automate the boring stuff with python> regular strong passwords Examples

The book questions the practice of strong password 7.18

Write a function that uses regular expressions to ensure that the string passed in password is a strong password. The definition of a strong password is:

No less than eight characters in length, contain both uppercase and lowercase characters, at least one digit.

You may need to test the string expressions with more positive, in order to ensure its strength.

1 recommended wording closer to the book more regular and better understand the meaning, writing 2 online reference zero-width assertion.

Note that the wording of the case 1 match to be separated, if written as [a-zA-Z] will only match uppercase and lowercase characters can be one, while the case has not satisfied

1  # ! Python3 
2  # 7.18.1 definition of a strong password is: no less than eight characters in length, contain both uppercase and lowercase characters, at least one digit. 
3  # You may need to test the string expressions with more positive, in order to ensure its strength. 
. 4  
. 5  Import Re
 . 6 the passwd = STR (INPUT ( ' Enter the passwd A: ' ))
 . 7 RE1 = the re.compile (R & lt ' .. 8 {,} ' )
 . 8 RE2 = the re.compile (R & lt ' [AZ] ' )
 . 9 = the re.compile RE3 (R & lt ' \ + D ' )
 10 RE4 = the re.compile (R & lt ' [AZ] ' )
 . 11  
12 is #写法2
13 #re9=re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$')
14 
15 if re1.search(passwd) and re2.search(passwd) and re3.search(passwd) and re4.search(passwd):
16 #if re9.search(passwd):
17     print('passwd is strong enough')
18 else:
19     print('passwd need upper,lower,number and more than 8')

 

Guess you like

Origin www.cnblogs.com/chenzhefan/p/11932988.html