HJ87 密码强度等级

# HJ87 密码强度等级
def classOfpassword(password):
    num, up_char, down_char, other, score = 0, 0, 0, 0, 0
    srt_data = password.strip()
    for char in srt_data:
        if char.isdigit():    # 判断是否是数字
            num += 1
        elif char.isalpha():    # 判断是否是字母
            if char.upper() == char:
                up_char += 1    # 大写字母
            else:
                down_char += 1    # 小写字母
        else:
            other += 1    # 符号
    # 密码长度
    if len(srt_data) < 5:
        score += 5
    elif len(srt_data) < 8:
        score += 10
    else:
        score += 25
    # 密码大小写
    if up_char == 0 and down_char == 0:
        pass
    elif (up_char != 0 and down_char == 0) or (up_char == 0 and down_char != 0):
        score += 10
    else:
        score += 20
    # 密码数字个数
    if num == 0:
        pass
    elif num == 1:
        score += 10
    else:
        score += 20
    # 符号个数
    if other == 0:
        pass
    elif other == 1:
        score += 10
    else:
        score += 25
    # 奖励
    if num != 0 and (up_char + down_char) != 0 and other == 0:
        score += 2
    elif num != 0 and up_char != 0 and down_char != 0 and other != 0:
        score += 5
    elif num != 0 and (up_char + down_char) != 0 and other != 0:
        score += 3
    if score >= 90:
        return ('VERY_SECURE')
    elif score >= 80:
        return 'SECURE'
    elif score >= 70:
        return 'VERY_STRONG'
    elif score >= 60:
        return 'STRONG'
    elif score >= 50:
        return 'AVERAGE'
    elif score >= 25:
        return 'WEAK'
    else:
        return 'VERY_WEAK'


if __name__ == '__main__':
    inputstr1 = input('Enter a string: ')
    # inputstr2 = input('Enter a string: ')
    # inputnum = int(input('Enter a number: '))
    print(classOfpassword(inputstr1))

你可能感兴趣的:(python,开发语言)