题解 | #密码强度等级#

密码强度等级

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

import re
while True:
    try:
        words= input()
    except:
        break
    else:
        num  = len(words)
        scores =0
        dic_c ={'low_alpha':0,'upper_alpha':0,'number':0,'ss':0}
        string = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
        ## 1. length
        if num <=4:
            scores+=5
        elif num>=5 and num <=7:
            scores+=10
        else:
            scores+=25
        ##2. alpha number
        for word in words:
            if word.isalpha():
                if word.islower():
                    dic_c['low_alpha']+=1
                if word.isupper():
                    dic_c['upper_alpha']+=1
            elif word.isdigit():
                dic_c['number']+=1
            elif word in string:
                dic_c['ss']+=1

        if dic_c['low_alpha']>0 and dic_c['upper_alpha']>0:
            scores+=20
        elif dic_c['low_alpha']>0 or dic_c['upper_alpha']>0:
            scores+=10
        else:
            scores+=0
            
        if dic_c['number']>1:
            scores+=20
        elif dic_c['number']==1:
            scores+=10
        else:
            scores+=0

        ## 3. 
        if dic_c['ss']==1:
            scores+=10
        elif dic_c['ss']>1:
            scores+=25
        
        # reward
        if dic_c['number']>0:
            if dic_c['low_alpha']>0 and dic_c['upper_alpha']>0:
                if dic_c['ss']>0:
                    scores+=5
            elif dic_c['low_alpha']>0 or dic_c['upper_alpha']>0:
                if dic_c['ss']>0:
                    scores+=3
                else:
                    scores+=2
        if scores >=90:
            print("VERY_SECURE")
        elif scores >=80:
            print("SECURE")
        elif scores >=70:
            print("VERY_STRONG")
        elif scores >=60:
            print("STRONG")
        elif scores >=50:
            print("AVERAGE")
        elif scores >= 25:
            print("WEAK")
        elif scores >= 0:
            print("VERY_WEAK")
         
全部评论

相关推荐

jack_miller:我给我们导员说我不在这里转正,可能没三方签了。导员说没事学校催的时候帮我想办法应付一下
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务