incorrectPassword= True
while incorrectPassword:
password = input("type in your password: ")
if len(password) < 8:
print("your password must be 8 characters long")
if len(password) >24:
print("Your password must be shorter than 24 characters")
elif not any(i.isdigit() for i in password):
print("you need a number in your password")
elif not any(i.isupper() for i in password):
print("you need a capital letter in your password")
elif not any(i.islower() for i in password):
print("you need a lowercase letter in your password")
incorrectPassword = False
如何根据需要仅允许某些字符(如!, $, %, ^, &, *, (, ), -, _, =
或+
)?
答案 0 :(得分:0)
答案 1 :(得分:0)
我会使用正则表达式,但要以与其他测试类似的方式进行:
any(i not in '!$%^&*()-_=+' for i in password)