真的是极度不优雅。。。

密码强度等级

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

def s_lo(a):
    if len(a) <= 4:
        s_long = 5
    elif len(a) >= 5 and len(a) <= 7:
        s_long = 10
    else:
        s_long = 25
    return s_long


def s_le(a):
        flag1 = 0
        flag2 = 0
        for i in a:
            if ord(i) >= ord('a') and ord(i) <= ord('z'):
                flag1 = 1
            if ord(i) >= ord('A') and ord(i) <= ord('Z'):
                flag2 = 1
        if flag1 == 0 and flag2 == 0:
            s_letter = 0
        elif (flag1 == 1 and flag2 == 0) or (flag1 == 0 and flag2 == 1):
            s_letter = 10
        elif flag1 == 1 and flag2 == 1:
            s_letter = 20

        return s_letter


def s_nu(a):
    count = 0
    for i in a:
        if i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
            count += 1
    if count == 0:
        s_num = 0
    elif count > 1:
        s_num = 20
    else:
        s_num = 10

    return s_num


def s_sy(a):
    count = 0
    for i in a:
        if (ord(i) >= ord('!') and ord(i) <= ord('/')) or (ord(i) >= ord(':') and ord(i) <= ord('@')) or (
            ord(i) >= ord('[') and ord(i) <= ord('`')) or (ord(i) >= ord('{') and ord(i)<= ord('~')):
            count += 1
    if count == 0:
        s_symble = 0
    elif count > 1:
        s_symble = 25
    else:
        s_symble = 10

    return s_symble

while True:
    try:
        a = input().strip()
        s_long = s_lo(a)
        s_letter = s_le(a)
        s_num = s_nu(a)
        s_symble = s_sy(a)
        reward = 0

        if (s_num != 0 and s_letter != 0 and s_symble == 0):
            reward = 2
        if(s_num != 0 and s_letter != 0 and s_symble != 0):
            reward = 3
        if (s_num != 0 and s_letter == 20 and s_symble != 0):
            reward = 5
        score = s_long + s_letter + s_num + s_symble + reward
        if score >= 90:
            print('VERY_SECURE')
        elif score >= 80 and score < 90:
            print('SECURE')
        elif score >= 70 and score < 80:
            print('VERY_STRONG')
        elif score >= 60 and score < 70:
            print('STRONG')
        elif score >= 50 and score < 60:
            print('AVERAGE')
        elif score >= 25 and score < 50:
            print('WEAK')
        elif score >= 0 and score < 25:
            print('VERY_WEAK')
    except:
        break
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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