题解 | 密码强度等级

import sys

ke = input()
s = 0
if len(ke)< 5:
    s += 5
elif  5<= len(ke) < 8:
    s += 10
else:  
    s += 25

count_n, count_f,count_lower_a,count_upper_a = 0,0,0,0

for i in ke:
    if i in "0123456789":
        count_n +=1
    elif i in "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~":
        count_f +=1
    elif i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        count_upper_a +=1
    elif i in "abcdefjhijklmnopqrstuvwxyz":
        count_lower_a +=1
count_a = count_lower_a + count_upper_a

if count_n ==1:
    s +=10
elif count_n > 1:
    s +=20

if count_f ==1:
    s +=10
elif count_f > 1:
    s +=25

if count_lower_a>0 and count_upper_a >0:
    s +=20
elif count_lower_a>0 or count_upper_a >0:
    s +=10

if count_lower_a>0 and count_upper_a>0 and count_n>0 and count_f>0:
    s +=5
elif count_n>0 and count_a>0 and count_f>0:
    s +=3
elif count_n>0 and count_a>0 and count_f==0:
    s +=2

def pingfen(x):
    if x >= 90:
        return "VERY_SECURE"
    elif x >= 80:
        return "SECURE"
    elif x >= 70:
        return "VERY_STRONG"
    elif x >= 60:
        return "STRONG" 
    elif x >= 50:
        return "AVERAGE" 
    elif x >= 25:
        return "WEAK" 
    else:
        return "VERY_WEAK" 

print(pingfen(s))

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务