In this program, we will check the validity of password input by users.
Steps to solve the program
- Import re library.
- Take input through the user.
- Check the validity of the password by using re.search() and while loop.
- Test the given conditions.
- Print the output.
import re
p = input("Input your password: ")
state = True
while True:
if (len(p)<5 or len(p)>15):
break
elif not re.search("[a-z]",p):
break
elif not re.search("[0-9]",p):
break
elif not re.search("[A-Z]",p):
break
elif not re.search("[$#@]",p):
break
elif re.search("\s",p):
break
else:
print("Valid Password")
state = False
break
if state:
print("Not a Valid Password")
Output :
Input your password: Sqatools#1@
Valid Password