题解 | #密码强度等级#

密码强度等级

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

levels = {
    90 : 'VERY_SECURE',
    80 : 'SECURE',
    70 : 'VERY_STRONG',
    60 : 'STRONG',
    50 : 'AVERAGE',
    25 : 'WEAK',
    0 : 'VERY_WEAK'
}

def get_score(c):
    score = 0
    # 长度
    if len(c) >= 8:
        score += 25
    elif 5 <= len(c) <= 7:
        score += 10
    else:
        score += 5
    for l in c:
        if l.isupper():
            dic['upper'] += 1
        elif l.islower():
            dic['lower'] += 1
        elif l.isdigit():
            dic['digit'] += 1
        else:
            dic['sym'] += 1
    # 字母
    if dic['upper'] and dic['lower']:
        score += 20
    else:
        score += 10
    # 数字
    if dic['digit'] > 1:
        score += 20
    elif dic['digit'] == 1:
        score += 10
    # 符号
    if dic['sym'] > 1:
        score += 25
    elif dic['sym'] == 1:
        score += 10
    # 奖励
    if dic['upper'] and dic['lower'] and dic['digit'] and dic['sym']:
        score += 5
    elif (dic['upper'] or dic['lower']) and dic['digit'] and dic['sym']:
        score += 3
    elif (dic['upper'] or dic['lower']) and dic['digit']:
        score += 2
    return score
    
while True:
    try:
        dic = {
            'upper' : 0,
            'lower' : 0,
            'digit' : 0,
            'sym' : 0
        }
        code = input()
        score = get_score(code)
        for k in sorted(levels.keys(), key=lambda x : x, reverse=True):
            if score >= k:
                print(levels[k])
                break
    except:
        break
全部评论

相关推荐

评论
点赞
1
分享

创作者周榜

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