题解 | #密码强度等级#

密码强度等级

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

import sys
import re

for line in sys.stdin:
    pwd = line.strip()
    score = 0
    length = len(pwd)
    digit, word, symbol = 0, 0, 0
    if length <= 4:
        score += 5
    elif length <= 7:
        score += 10
    else:
        score += 25
    
    # print(score)

    words = re.findall('[a-zA-Z]+', pwd)
    # print(words)
    if len(words) >= 1:
        word += 1
        if not re.search('[a-z]', pwd) or not re.search('[A-Z]', pwd):
            score += 10
        else:
            word += 1
            score += 20

    # print(word, score)

    nums = re.findall('[0-9]+', pwd)
    # print(nums)
    if len(''.join(nums)) == 1:
        digit += 1
        score += 10
    elif len(''.join(nums)) > 1:
        digit += 1
        score += 20
    
    # print(digit, score)

    symbols = re.findall('[^0-9a-zA-Z]', pwd)
    # print(symbols)
    if len(''.join(symbols)) == 1:
        symbol += 1
        score += 10
    elif len(''.join(symbols)) > 1:
        symbol += 1
        score += 25

    # print(symbol, score)

    bonus = digit + word + symbol
    if bonus == 4:
        score += 5
    elif bonus == 3 and word == 1:
        score += 3
    else:
        score += 2
    
    # print(digit, word, symbol, score)

    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')

全部评论

相关推荐

鼗:四级有点难绷,感觉能拿国家励志奖学金,学习能力应该蛮强的,四级确实不重要,但是拿这个卡你可是很恶心啊
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务