def check_password(pw):
global reason
while True:
if not re.search(string.ascii_lowercase,pw):
flag = False
reason = get_error(4)
break
elif not re.search(string.ascii_uppercase, pw):
flag = False
reason = get_error(1)
break
elif not re.search(string.digits, pw):
flag = False
reason = get_error(2)
break
elif not re.search(string.punctuation, pw):
flag = False
reason = get_error(3)
break
else:
flag = True
print("Valid Password")
break
return flag
flag = False
min_length = 5
#password = input("Please enter your password:")
password = getpass.getpass("Enter Password:")
if len(password) >= min_length:
check_password(password)
print(password)
if flag == True:
print("Valid Password!")
else:
print(reason)
else:
print("Your password is not long enough.")
Here I am using regex to validate a password. I was successful if I hardcode the pattern "[A-Z]", "[0-9]", but now if I use string library constants, I am getting the message from the 1st check, irrespective of anything else wrong in the password.
Can you tell me where I am wrong, syntactically or semantically?