描述
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符
二、字母:
0 分: 没有字母
10 分: 密码里的字母全都是小(大)写字母
20 分: 密码里的字母符合”大小写混合“
三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字
四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号
五、奖励(只能选符合最多的那一种奖励):
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号
最后的评分标准:
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0: 非常弱(Very_Weak)
对应输出为:
VERY_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK
请根据输入的密码字符串,进行安全评定。
注:
字母:a-z, A-Z
数字:0-9
符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)
!"#$%&'()*+,-./ (ASCII码:0x21~0x2F)
:;<=>?@ (ASCII码:0x3A~0x40)
[\]^_` (ASCII码:0x5B~0x60)
{|}~ (ASCII码:0x7B~0x7E)
提示:
1 <= 字符串的长度<= 300
输入描述:
输入一个string的密码
输出描述:
输出密码等级
示例1
输入:
38$@NoNoN
复制输出:
VERY_SECURE
复制说明:
样例的密码长度大于等于8个字符,得25分;大小写字母都有所以得20分;有两个数字,所以得20分;包含大于1符号,所以得25分;由于该密码包含大小写字母、数字和符号,所以奖励部分得5分,经统计得该密码的密码强度为25+20+20+25+5=95分。
示例2
输入:
Jl)M:+
复制输出:
AVERAGE
复制说明:
示例2的密码强度为10+20+0+25+0=55分。
s = input()
count = 0
if len(s) <= 4:
count += 5
elif len(s) >= 5 and len(s) <= 7:
count += 10
else:
count += 25
zm = []
flag = False
for i in s:
if i.isalpha():
zm.append(i)
break
if not zm:
count += 0
elif s.isupper() or s.islower():
count += 10
else:
count += 20
flag = True
sz = []
for i in s:
if i.isdigit():
sz.append(i)
if not sz:
count += 0
elif len(sz) == 1:
count += 10
else:
count += 20
sfh = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ """
fh = []
for i in s:
if i in sfh:
fh.append(i)
if not fh:
count += 0
elif len(fh) == 1:
count += 10
else:
count += 25
if zm and sz and fh and flag:
count += 5
elif zm and sz and fh:
count += 3
elif zm and sz:
count += 2
else:
pass
# print(count)
if count >= 0 and count < 25:
print("VERY_WEAK")
elif count >= 25 and count < 50:
print("WEAK")
elif count >= 50 and count < 60:
print("AVERAGE")
elif count >= 60 and count < 70:
print("STRONG")
elif count >= 70 and count < 80:
print("VERY_STRONG")
elif count >= 80 and count < 90:
print("SECURE")
else:
print("VERY_SECURE")
或者
while True:
try:
password_string = input()
score = 0
if len(password_string) >= 8: # 针对密码长度
score = 25
elif 4 < len(password_string) < 8:
score = 10
elif len(password_string) <= 4:
score = 5
isdigit = 0 # 判断是否有数字
isalpha = 0 # # 判断是否有字母
teshu = 0 # 特殊字符
isalpha_upper = 0 # 字母大写
isalpha_lower = 0 # 字母小写
for i in password_string:
if i.isdigit():
isdigit += 1
elif i.isalpha():
isalpha += 1
if ord(i) < 97: # assi码小于97 为 大写
isalpha_upper += 1
else:
isalpha_lower += 1
else:
teshu += 1
if isalpha > 0: # 有字母
if isalpha_upper != 0 and isalpha_lower != 0: # 且有大小写字母
score += 20
else: # 只有大写或者小写字母
score += 10
if 2 > isdigit > 0:
score += 10
elif isdigit >= 2:
score += 20
if 2 > teshu > 0:
score += 10
elif teshu >= 2:
score += 25
if isalpha_upper != 0 and isalpha_lower != 0 and isdigit != 0 and teshu != 0: # 奖励
score += 5
elif isalpha != 0 and isdigit != 0 and teshu != 0:
score += 3
elif isalpha != 0 and isdigit != 0:
score += 2
if score >= 90:
print("VERY_SECURE")
elif score >= 80:
print("SECURE")
elif score >= 70:
print("VERY_STRONG")
elif score >= 60:
print("STRONG")
elif score >= 50:
print("AVERAGE")
elif score >= 25:
print("WEAK")
else:
print("VERY_WEAK")
except:
break