一、题目


二、示例

三、代码
while True:
try:
str1 = input()
result = 0
# 密码长度
if len(str1) <= 4:
result += 5
elif len(str1) >= 8:
result += 25
else:
result += 10
word_uper = 0
word_lower = 0
num = 0
signal = 0
# 遍历字符串
for item in str1:
if item.islower():
word_lower += 1
elif item.isupper():
word_uper += 1
elif item.isdigit():
num += 1
else:
signal += 1
# 判断字母情况
if word_lower == 0 and word_uper == 0:
result += 0
elif word_lower > 0 and word_uper > 0:
result += 20
else:
result += 10
# 判断数字情况
if num == 0:
result += 0
elif num == 1:
result += 10
else:
result += 20
# 判断符号情况
if signal == 0:
result += 0
elif signal == 1:
result += 10
else:
result += 25
# 判断奖励情况
if word_lower > 0 and word_uper > 0 and num > 0 and signal > 0:
result += 5
if (word_lower > 0 and num > 0 and signal > 0) or (word_uper > 0 and num > 0 and signal > 0):
result += 3
else:
result += 2
# 评分标准
if result >= 90:
print('VERY_SECURE')
if 80 <= result < 90:
print('SECURE')
if 70 <= result < 80:
print('VERY_STRONG')
if 60 <= result < 70:
print('STRONG')
if 50 <= result < 60:
print('AVERAGE')
if 25 <= result < 50:
print('WEAK')
if 0 <= result < 25:
print('VERY_WEAK')
except:
break
四、算法说明
- 计算密码长度的得分;
- 建立四个计数值:
word_uper,word_lower,num,signal,分别表示大写字母、小写字母、数字、符号四种字符的个数; - 遍历字符串,将对应的字符个数,统计出来;
- 根据统计的计数值,判断奖励的情况;
- 根据最后的得分值,判断密码强度。
胡萝卜
编辑时间:2022年1月21日20:06:12
| 我不知道将去向何方,但我已在路上! |
|---|
| 时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |
本文介绍了一种密码强度评估算法,通过计算密码长度、字符类型分布及组合奖励,给出密码安全等级。通过实例演示了如何使用代码判断密码强度,并详细解读了评分标准。

1万+

被折叠的 条评论
为什么被折叠?



