char=list()
upper=【c for c in char if 'A'<=c and c<='Z' 】可以快速筛选出列表char里的大写字符
lower=【c for c in char if 'a'<=c and c<='z'】可以快速筛选出列表char里的小写字符
digit=【c for c in char if 0<=c and 0<=9】可以快速筛选出列表char里的数字
symbol=【c for c in char if not( 'A'<=c and c<='Z' or 'a'<=c and c<='z' or 0<=c and 0<=9 )】
可以快速筛选出除字母数字外的其他字符
strong=len(upper)>=1 and len(lower)>=1 and len(digit)>=3 and len(symbol)>=3 and len(char)>=12也省了好多个if语句,使代码行数减少好多,代码简洁好多。
Python编程好简单啊,代码好漂亮啊
'''
检测密码强度
强密码条件:大写字母>=1,小写字母>=1,数字>=3,其他字符>=3,总长>=12
主要知识点:从一个列表里挑出特殊字符组成一个新列表
'''
def isStrongPassword(pwd):
chars=list(pwd)
upper=[c for c in chars if 'A'<=c and c<='Z']
lower=[c for c in chars if 'a'<=c and c<='z']
digit=[c for c in chars if '0'<=c and c<='9']
symbol=[c for c in chars if not('A'<=c and c<='Z' or 'a'<=c and c<='z'or'0'<=c and c<='9')]
strong=len(upper)>=1 and len(lower)>=1 and len(digit)>=3 and len(symbol)>=3 and len(pwd)>=12
print(upper)
print(lower)
print(digit)
print(symbol)
return strong
print(isStrongPassword('StrOn9P@$^12'))
print(isStrongPassword('trOn9P@$^12'))