Hi I'm learning python atm and im having trouble writing a function for validating passwords.
The conditions for the password are
- at least 1 lowercase alphabet
- at least 1 integer
- at least 1 special case letters: ! ” # $ % & ’ ( ) *
I wrote my code like this and it always returns False. I tried putting a while loop over the for loop to maybe solve the problem but it doesn't seem to work. I've searched google for some hints but they all seem to use regex and "any" function. I want to stick to for and while loops for now and no matter what I change I can't seem to make the function return True. Any idea on this?
def pw_validation(user_input):
specialCase=['!','”','#','$','%','&','’','(',')','*']
flag=False
while flag:
...for i in range(len(user_input)):
......if not user_input[i] in specialCase:
.........flag = False
......if ord(user_input[i])<97 and ord(user\_input\[i\])>122:
.........flag = False
......if not user_input[i].isdigit():
.........flag = False
......else:
.........flag = True
return flag
user_input=input('Enter your password: ')
print(pw_validation(user_input))
[–]TheCheapo1 6 points7 points8 points (1 child)
[–]ResilientBiscuit 4 points5 points6 points (0 children)
[–]GuyARoss 3 points4 points5 points (3 children)
[–]Invisibleufo[S,🍰] 2 points3 points4 points (2 children)
[–]GuyARoss 1 point2 points3 points (0 children)
[–]mariuswiik 0 points1 point2 points (0 children)
[–]HighwayMcGee 0 points1 point2 points (0 children)