题解 | #密码强度等级#

密码强度等级

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

while True:
    try:
        str1 = input()
        result = 0
        # 密码长度
        if len(str1) <= 4:
            result += 5
        elif len(str1) >= 8:
            result += 25
        else:
            result += 10
        word_uper = 0
        word_lower = 0
        num = 0
        signal = 0
        # 遍历字符串
        for item in str1:
            if item.islower():
                word_lower += 1
            elif item.isupper():
                word_uper += 1
            elif item.isdigit():
                num += 1
            else:
                signal += 1
        # 判断字母情况
        if word_lower == 0 and word_uper == 0:
            result += 0
        elif word_lower > 0 and word_uper > 0:
            result += 20
        else:
            result += 10
        # 判断数字情况
        if num == 0:
            result += 0
        elif num == 1:
            result += 10
        else:
            result += 20
        # 判断符号情况
        if signal == 0:
            result += 0
        elif signal == 1:
            result += 10
        else:
            result += 25
        # 判断奖励情况
        if word_lower > 0 and word_uper > 0 and num > 0 and signal > 0:
            result += 5
        if (word_lower > 0 and num > 0 and signal > 0) or (word_uper > 0 and num > 0 and signal > 0):
            result += 3
        else:
            result += 2
        # 评分标准
        if result >= 90:
            print('VERY_SECURE')
        if 80 <= result < 90:
            print('SECURE')
        if 70 <= result < 80:
            print('VERY_STRONG')
        if 60 <= result < 70:
            print('STRONG')
        if 50 <= result < 60:
            print('AVERAGE')
        if 25 <= result < 50:
            print('WEAK')
        if 0 <= result < 25:
            print('VERY_WEAK')
    except:
        break
全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-11 13:34
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

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