因为你如果重新输入密码就不会执行判断密码强度的代码(因为程序还在 while 循环中),改成这样就可以了:
times = 3
while times > 0:
print('--------密码安全检查---------')
# 字符数小于8 或由纯数字字母组成的为低级密码
# 字符数量大于8小于16且由数字、字母、特殊字符其中两种组成的为中级密码
# 字符数量大于16且由数字、字母、特殊字符 三种组成,开头必须为字母的为高级密码
# 特殊字符仅限:~!@#$%^&*()_=-/,.?<>;:[]{}|\|'";:/?,.<>
sp = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''
figure = '0123456789'
letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
password = input('请输入您设置的密码:')
length = len(password)
while (password.isspace() or length == 0):
print('请正确输入您的密码,谢谢\n')
password = input('请重新输入您的密码:')
length = len(password)
# 判断长度
if length < 8:
flag_len = 1
elif 16 > length > 8:
flag_len = 2
else:
flag_len = 3
flag_sp = 0 # 特殊字符等级
flag_fi = 0 # 数字等级
flag_le = 0 # 字母等级
flag_one = 0 # 首个字符是否为字母
# 判断特殊字符
for each in password:
if each in sp:
flag_sp += 1
break
# 判断数字
for each in password:
if each in figure:
flag_fi += 1
break
# 判断字母
for each in password:
if each in letter:
flag_le += 1
break
flag_zucheng = flag_sp + flag_fi + flag_le
flag_fl = flag_fi + flag_le
# 判断开头是否为字母
if password[0] in letter:
flag_one += 1
print("您的密码安全级别评定为:")
if (flag_len == 1) or (flag_sp == 0 and flag_fl == 1):
print('低!真垃圾!')
elif (flag_zucheng == 3) and (flag_len == 3) and (flag_one == 1):
print('beautiful,你的密码强度很高,请继续保持')
break
else:
print('中等,勉强可以吧')
times -= 1
|