题解 | #密码强度等级#

密码强度等级

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

while True:
    try:
        pwd=input()
        pwd_len=len(pwd)
        pwd_Upalp,pwd_Lowalp,pwd_num,pwd_symbol=0,0,0,0
        lenscore,alpscore,numscore,symbolscore,otherscore,total_score=0,0,0,0,0,0
        # 计算各种字符的个数
        for i in pwd:
            if i.isupper()==True:
                pwd_Upalp+=1
            if i.islower()==True:
                pwd_Lowalp+=1
            if i.isnumeric()==True:
                pwd_num+=1
        pwd_symbol=pwd_len-pwd_Upalp-pwd_Lowalp-pwd_num

        # 计算长度分数
        if pwd_len<=4:
            lenscore=5
        elif 5<=pwd_len<=7:
            lenscore=10
        else:
            lenscore=25
        # 计算字母分数 
        if pwd_Upalp==0 and pwd_Lowalp==0:
            alpscore=0
        if (pwd_Upalp>0 and pwd_Lowalp==0)&nbs***bsp;(pwd_Upalp==0 and pwd_Lowalp>0):
            alpscore=10
        if pwd_Upalp>0 and pwd_Lowalp>0:
            alpscore=20
        # 计算数字分数 
        if pwd_num==0:
            numscore=0
        if pwd_num==1:
            numscore=10
        if pwd_num>1:
            numscore=20
        # 计算符号分数 
        if pwd_symbol==0:
            symbolscore=0
        if pwd_symbol==1:
            symbolscore=10
        if pwd_symbol>1:
            symbolscore=25
        # 计算奖励分数 
        if alpscore>0 and numscore>0 and symbolscore==0:
            otherscore=2
        if alpscore==10 and numscore>0 and symbolscore>0:
            otherscore=3
        if alpscore==20 and numscore>0 and symbolscore>0:
            otherscore=5
        # 计算总分数
        total_score=lenscore+alpscore+numscore+symbolscore+otherscore
        # 用来调试
        # print(pwd_Upalp,pwd_Lowalp,pwd_num,pwd_symbol)
        # print(lenscore,alpscore,numscore,symbolscore,otherscore,total_score)
        # 打印评分表
        if total_score>=90:
            print("VERY_SECURE")
        elif total_score>=80:
            print("SECURE")
        elif total_score>=70:
            print("VERY_STRONG")
        elif total_score>=60:
            print("STRONG")
        elif total_score>=50:
            print("AVERAGE")
        elif total_score>=25:
            print("WEAK")
        else:
            print("VERY_WEAK")
    except:
        break


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务