import string
def check(pwd):
if not isinstance(pwd,str) or len(pwd) < 6:
return '密码格式错误'
#密码强度等级
d={1:'weak', 2:'below middle', 3:'above middle', 4:'strong'}
#标记是否含有数字、小写、大写、特殊符号
ind = [0]*4
for ch in pwd:
#检查数字
if not ind[0] and ch in string.digits:
ind[0] = 1
elif not ind[1] and ch in string.ascii_lowercase:
ind[1] = 1
elif not ind[2] and ch in string.ascii_uppercase:
ind[2] = 1
# elif not ind[3] and ch in string.punctuation:
elif not ind[3] and ch in '+-*/,.?':
ind[3] = 1
return d.get(sum(ind),'error')
print(check('QWe1234+-'))
检查字符串安全强度
猜你喜欢
转载自blog.csdn.net/baidu_41867252/article/details/86063110
今日推荐
周排行