用户输入一个字符串做为密码,判断密码强度,规则为:密码长度小于8弱密码,密码长度大于等于8且包含至少2种字符为中等强度、密码包含3种字符为强、包含全部4种字符为极强。
提示:
string.digits 可返回’0123456789’
string.ascii_lowercase 可返回’abcdefghijklmnopqrstuvwxyz’
string.ascii_uppercase 可返回’ABCDEFGHIJKLMNOPQRSTUVWXYZ’
string.punctuation 可返回’!"#$%&’()*+,-./:;<=>?@[\]^_`{|}~’
import string
a=list(input(""))
digits=[]
ascii_lowercase=[]
ascii_uppercase=[]
punctuation=[]
count=0
if len(a)<8:
print("弱")
elif len(a)>=8:
for i in a:
if i in string.digits :
digits.append(i)
if i in string.ascii_lowercase :
ascii_lowercase.append(i)
if i in string.ascii_uppercase :
ascii_uppercase.append(i)
if i in string.punctuation:
punctuation.append(i)
#判断运用了哪些字符方式,并用标志count表示
if digits:
count=count+1
if ascii_lowercase:
count=count+1
if ascii_uppercase:
count=count+1
if punctuation:
count=count+1
#通过count的值可以知道运用了多少种,以此来判断强度
if count==2:
print("中")
if count==3:
print("强")
if count==4:
print("极强")
结果:
123sdf
弱
***Repl Closed***
12345678Aa!
极强
***Repl Closed***