-2
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

How can I only allow certain characters (like !, $, %, ^, &, *, (, ), -, _, = or +) as needed input?

waka
  • 3,362
  • 9
  • 35
  • 54
Ejay
  • 1
  • 1

2 Answers2

0

you can simply use

elif " " in password:
    #print error

or use Python's re package to define what characters are allowed in your password

mantkowicz
  • 26
  • 1
0

I would use regex, but to do it in a similar fashion to your other tests:

any(i not in '!$%^&*()-_=+' for i in password)
Paco H.
  • 2,034
  • 7
  • 18