题解 | #密码强度等级#

密码强度等级

https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361?tpId=37&tqId=21310&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D2%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=2&judgeStatus=undefined&tags=&title=

  • 写起来还是相当复杂的
passwd = input()
n = len(passwd)

# 密码长度
ans = 0
if n <= 4:
    ans += 5
elif n <= 7:
    ans += 10
else:
    ans += 25

digits = 0
lower, upper = False, False
symbol = 0

for ch in passwd:
    if ch.isupper():
        upper = True
    if ch.islower():
        lower = True
    if ch.isdigit():
        digits += 1
    if (
        0x21 <= ord(ch) <= 0x2F
        or 0x3A <= ord(ch) <= 0x40
        or 0x5B <= ord(ch) <= 0x60
        or 0x7B <= ord(ch) <= 0x7E
    ):
        symbol += 1

if lower and upper:
    ans += 20
elif lower or upper:
    ans += 10

if digits > 1:
    ans += 20
elif digits == 1:
    ans += 10

if symbol > 1:
    ans += 25
elif symbol == 1:
    ans += 10

if digits > 0:
    if lower and upper and symbol > 0:
        ans += 5
    elif symbol > 0 and (lower or upper):
        ans += 3
    elif lower or upper:
        ans += 2

# 评分
if ans >= 90:
    print("VERY_SECURE")
elif ans >= 80:
    print("SECURE")
elif ans >= 70:
    print("VERY_STRONG")
elif ans >= 60:
    print("STRONG")
elif ans >= 50:
    print("AVERAGE")
elif ans >= 25:
    print("WEAK")
elif ans >= 0:
    print("VERY_WEAK")

全部评论

相关推荐

10-25 12:05
已编辑
湖南科技大学 Java
若梦难了:我有你这简历,已经大厂乱杀了
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务