(1)密码必须至少包含6个字符;
(2)密码强度等级与包含字符种类的对应关系。如果密码字符串包含小写字母、大写字母、数字、标点符号中的4种,为强密码;包含3种表示中高强度,2种表示中低强度,1种为弱密码;
如果输入长度不够或者四种都不包含给出错误提示,否则给出强度等级。
from string import ascii_lowercase, ascii_uppercase, digits
key = input("请输入密码")
really_key = set(key)
new_set = set(ascii_lowercase) | set(ascii_uppercase) | set(digits) | set("\",.?!\';:")
result_1 = really_key.issubset(new_set) # 判断really_key是不是new_set的子集,是则为Ture
if len(key) < 6:
print("输入错误,密码长度不够")
else:
if not result_1:
print("输入错误,密码不符合要求")
else:
exist = [set(ascii_lowercase), set(ascii_uppercase), set(digits), set("\",.?!\';:")]
level = {1: '弱密码', 2: '中低强度密码', 3: '中高强度密码', 4: '强密码'}
count = 0
for i in range(4):
result = really_key.isdisjoint(exist[i]) # 有相同则False
while not result:
count += 1
break
print(level[count])
演示结果: