我试图做一个密码检查器,要求用户输入一个介于8到24个字符之间的密码(如果超出这个范围,将显示一条错误消息)。另外,根据用户输入的密码长度进行加减。在
If there is at least one 'capital', 'lower case', 'symbol' or 'number': add 5 points.
If there is a capital and a number and a lower: add 15 points.
If entered password is in the form of 'QWERTY': subtract 15 points.
以下是我目前为止的代码:
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
你可以试试这个:
相关问题 更多 >
编程相关推荐