题解 | #密码强度等级#

密码强度等级

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

全部评论

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
快刀斩offer:干测试,项目组就我一个测试,准备在职考研跑路了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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