1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 让用户输入密码字符串 并使用两种方法(使用集合)检查并判断密码字符串的安全强度。

让用户输入密码字符串 并使用两种方法(使用集合)检查并判断密码字符串的安全强度。

时间:2022-12-18 05:04:12

相关推荐

让用户输入密码字符串 并使用两种方法(使用集合)检查并判断密码字符串的安全强度。

(1)密码必须至少包含6个字符;

(2)密码强度等级与包含字符种类的对应关系。如果密码字符串包含小写字母、大写字母、数字、标点符号中的4种,为强密码;包含3种表示中高强度,2种表示中低强度,1种为弱密码;

如果输入长度不够或者四种都不包含给出错误提示,否则给出强度等级。

from string import ascii_lowercase, ascii_uppercase, digitskey = 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的子集,是则为Tureif 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 = 0for i in range(4):result = really_key.isdisjoint(exist[i]) # 有相同则Falsewhile not result:count += 1breakprint(level[count])

演示结果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。