I am coding a password checker for an assignment. Here are the requirements:
At least 2 letter between [a-z] and 1 letter between [A-Z]. At least 1 number between [0-9]. At least 1 character from [?$#@]. Minimum length 10 characters. Maximum length 14 characters. Moreover, in case of invalid password, the program should keep on asking for new password unless it validates it successfully.
For some odd reason, my code ignores the while loop conditions and jumps out of it after completing the for loop. What am I doing wrong and how could I fix this? Any help is appreciated!
import string
#password
password = input("Enter a password that has at least two lower case letter, one upper case letter, one number between one and nine, and one of the following characters: '?$#@.'")
#requirements
ll = list(string.ascii_lowercase)
ul = list(string.ascii_uppercase)
nums = ["1","2","3","4","5","6","7","8","9"]
char = ["?","$","#","@"]
#counters
llcounter = 0
ulcounter = 0
numscounter = 0
charcounter = 0
while llcounter < 2 or ulcounter < 1 or numscounter < 1 or charcounter < 1:
if len(password) > 10 and len(password) < 14:
for x in password:
if x in ll:
llcounter += 1
elif x in ul:
ulcounter += 1
elif x in nums:
numscounter += 1
elif x in char:
charcounter += 1
else:
password = input("Your password has not met the requirements, please try another one.")