还需要在第二层 while 中对 length 进行重新赋值:
symbols = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
nums = '0123456789'
while 1:
passwd = input('请输入需要检查的密码组合:')
length = len(passwd)
while passwd.isspace() or length == 0:
passwd = input('您输入的密码为空(或空格),请重新输入:')
length = len(passwd)
# 判断密码长度
if 0 < length <= 8:
flag_len = 1
elif 8 < length < 16:
flag_len = 2
else:
flag_len = 3
flag_con = 0
# 判断密码是否含有特殊字符
for each in passwd:
if each in symbols:
flag_con += 1
break
# 判断密码是否含有字母
for each in passwd:
if each in chars:
flag_con += 1
break
# 判断密码是否含有数字
for each in passwd:
if each in nums:
flag_con += 1
break
# 打印结果
while 1:
print('您的密码安全级别评定为:', end=' ')
if flag_len == 1 or flag_con == 1:
print('低')
elif flag_len == 2 or flag_con == 2:
print('中')
else:
print('高\n请继续保持~\n')
break
print("请按以下方式提升您的密码安全级别:\n\
1. 密码必须由数字、字母及特殊字符三种组合\n\
2. 密码只能由字母开头\n\
3. 密码长度不能低于16位\n")
break
|