+ 1

Please any one can help me to solve the password validation solution in python??

6th Jul 2020, 4:34 PM
Husnain Ansari
Husnain Ansari - avatar
4 ответов
+ 4
Your code works fine if ininput "1$asdGhX" and it responds: "strong password". What problem do you have?
6th Jul 2020, 6:12 PM
Lothar
Lothar - avatar
+ 2
Where is your attempt?
6th Jul 2020, 4:43 PM
HonFu
HonFu - avatar
+ 1
import re print("Enter the password") password=input() flag=0 while True: if(len(password)<8): flag=-1 break elif not re.search("[a-z]",password): flag=-1 break elif not re.search("[A-Z]",password): flag=-1 break elif not re.search("[]0-9]",password): flag=-1 break elif not re.search("[_@$]",password): flag=-1 break elif re.search("\s",password): flag=-1 break else: flag=0 print("strong password") break if flag==-1: print("Weak password,try again with other constraints")
6th Jul 2020, 4:45 PM
Husnain Ansari
Husnain Ansari - avatar
+ 1
assign variables equal to len(re.findall(one variable should look for a-zA-Z characters, the next for 0-9 characters, and finally one for special characters, which you ought to be able to figure out how to do yourself). Lets call these a, b, and c. Now you've got three variables that equal the number of each type of character in your input string. Next you can make an if statement that says if a is greater than or equal to whatever it needs to be, AND b is greater than whatever it needs to be, (repeat this for c, connecting all three with 'and'), then print ("whatever you need it to say in the event that the password is valid"). Obviously you add an else to print whatever it needs to say for an invalid password.
6th Jul 2020, 7:30 PM
Randy Ziegler
Randy Ziegler - avatar