201k views
2 votes
Write a program to ask the user to enter a password. Then check to see if it is a valid password based on these requirements: must be at least 8 characters long, must contain both uppercase and lowercase letters, must contain at least one number between 0-9, must contain a special character -!,@,#,$.

1 Answer

4 votes

Answer:

Step-by-step explanation:

def validatePassword(password):

specialChars = "-@$#"

digits = "0123456789"

hasDigit=False

hasSpecialCharacter=False

hasLowerCase = False

hasUperCase=False

for c in password:

if c in digits:

hasDigit=True

if c in specialChars:

hasSpecialCharacter=True

if c.islower():

hasLowerCase=True

if c.isupper():

hasUperCase=True

if hasUperCase and hasLowerCase and hasSpecialCharacter and hasDigit:

print(password,end='')

print("--------- valid password")

else:

print(password,end='')

print("--------- invalid password")

password = input("Enter Password: ")

validatePassword(password)

Write a program to ask the user to enter a password. Then check to see if it is a-example-1
User Conquester
by
4.4k points