【问题标题】:How to make a Password Checker?如何制作密码检查器?
【发布时间】:2018-03-19 16:35:21
【问题描述】:

我尝试制作密码检查器,要求用户输入 8 到 24 个字符之间的密码(如果超出此范围,则会显示错误消息)。另外,根据用户输入的密码长度加减积分。

如果至少有一个“大写”、“小写”、“符号”或“数字”: 加5分。

如果有大写和数字及以下:加15分。

如果输入的密码是'QWERTY'形式:减去15分。

到目前为止,这是我的代码:

passcheck = input("Enter a password to check: ") 

passlength = len(passcheck)

symbols = {'!','$','%','^','&','*','(',')','-','_','=','+'}
qwerty = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]

upper = sum(1 for character in passcheck if character.isupper())
lower = sum(1 for character in passcheck if character.islower())
num = sum(1 for character in passcheck if character.isnumeric())
sym = passcheck.count('!$%^&*()_-+=')

if passlength <8 or passlength >24:
    print("ERROR. Password must be between 8-24 characters long")
else:
    if upper in passcheck > 0:
        score += 5
    if lower in passcheck > 0:
        score += 5
    if num in passcheck > 0:
        score += 5

【问题讨论】:

    标签: python passwords


    【解决方案1】:

    你可以试试这个:

    import sys
    
    passcheck = input("Enter a password to check: ")
    
    checking=set(passcheck)
    
    passlength = len(passcheck)
    
    points=0
    
    symbols = {'!','$','%','^','&','*','(',')','-','_','=','+'}
    qwerty = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
    
    
    
    
    if passlength <8 or passlength >24:
        print("ERROR. Password must be between 8-24 characters long")
    
    
    else:
    
        for i in qwerty:
    
            if i in passcheck:  #If entered password is in the form of 'QWERTY': subtract 15 points.
                points-=15
                print("your password contain form of 'QWERTY' , Don't use weak password.")
                print(points)
                sys.exit()
    
    if any(i.islower() for i in checking) or any(i.isupper() for i in checking) or any(i for i in checking if i in symbols) or any(i.isdigit() for i in checking):
        points+=5  #If there is at least one 'capital', 'lower case', 'symbol' or 'number': add 5 points.
    
    
    if any(i.islower() for i in checking) and any(i.isupper() for i in checking) and any(i.isdigit() for i in checking):
        points+=15 #If there is a capital and a number and a lower: add 15 points.
    
    
    
    print(points)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-08
      • 2011-02-03
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多