题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

引用正则模块,方便判断

s=input()
def lens(s):
    lens_s=len(s)
    if lens_s<=4:
        score1=5
    elif lens_s>=8:
        score1=25
    else:
        score1=10
    return score1
def alpha(s):
    if not len(re.findall('[a-zA-Z]', s)):
        score2=0
    elif not len(re.findall('[a-z]', s)) and len(re.findall('[A-Z]', s)):
        score2=10
    elif not len(re.findall('[A-Z]', s)) and len(re.findall('[a-z]', s)):
        score2=10
    else:
        score2=20
    return score2
def num(s):
    if not len(re.findall('[\d]', s)):
        score3=0
    elif len(re.findall('[\d]', s))==1:
        score3=10
    else:
        score3=20
    return score3   
def fuhao(s):
    if not len(re.findall(r'''[!"#$%&'()*+,-./:;<=>?@[\]^_{|}~]''', s)):
        score4=0
    elif len(re.findall(r'''[!"#$%&'()*+,-./:;<=>?@[\]^_{|}~]''', s))==1:
        score4=10
    else:
        score4=25
    return score4
def award(s):
    score5=2
    if alpha(s)!=0 and num(s)!=0 and fuhao(s)!=0:
        score5=3
    if alpha(s)==20 and num(s)!=0 and fuhao(s)!=0:
        score5=5
    return score5
score=lens(s)+alpha(s)+num(s)+fuhao(s)+award(s)
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') 
elif score>=0:
    print('VERY_WEAK')                        
全部评论
终于看到一个正则的
点赞 回复 分享
发布于 2024-08-13 10:22 安徽

相关推荐

昨天 22:21
门头沟学院 Java
点赞 评论 收藏
分享
烤点老白薯:他第二句话的潜台词是想让你帮他点个瑞幸或者喜茶啥的
mt对你说过最有启发的一...
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务