Python program to check the validity of a password

Validation rules:-

At least 1 letter between [a-z] and 1 letter between [A-Z]

At least 1 number between [0-9]

At least 1 character from [$#@]

Minimum length 8 characters

code:-

import re
password= input("Input your password: ")
x = True
while x:  
    if (len(password)<8):
        break
    elif not re.search("[a-z]",password):
        break
    elif not re.search("[0-9]",password):
        break
    elif not re.search("[A-Z]",password):
        break
    elif not re.search("[$#@]",password):
        break
    elif re.search("\s",password):
        break
    else:
        print("Valid Password")
        x=False
        break
 
if x:
    print("Not a Valid Password")

output:-

Input your password: hello

Not a Valid Password

>>> 

Input your password: hello12345@

Not a Valid Password

>>> 

Input your password: Hello123@

Valid Password

>>> 


Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post