Password validation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Password validation

import re str = input() flag =0 while True: if (len(str)<6): flag =-1 break elif not re.search("[_@$]",str): flag =-1 break elif not re.search("[0-9]",str): flag =-1 break else: flag =0 print("Strong") break if flag == -1: print ('Weak') Pls tell what is wrong 😅

14th Oct 2020, 4:04 PM
Pritee
4 Answers
+ 4
For input = He!!00World Your code outputs = "Weak" Expected output = "Strong"
14th Oct 2020, 4:12 PM
Arsenic
Arsenic - avatar
+ 3
2 out of 13 failed
14th Oct 2020, 4:17 PM
Pritee
+ 1
import re str = input() flag =0 while True: if (len(str)<6): flag =-1 break elif not re.search("[_!#@%&*$]",str): flag =-1 break elif not re.search("[0-9]",str): flag =-1 break else: flag =0 print("Strong") break if flag == -1: print ('Weak') You just missed some of the special characters...which I have included..now your code works fine.. I hope it helps🙃
14th Oct 2020, 4:33 PM
ANJALI SAHU
0
password = list(input()) str = " ".join(password) #a string with space b/w the items import re symb = re.findall("[!@#\$%&\*]+", str) num = re.findall(r"[0-9]+", str) filt = filter((lambda x: x in symb,str), (password)) print ("Strong" if len(symb) >= 2 and len(num) >= 2 and len(password) >=7 else "Weak")
5th Dec 2021, 8:14 PM
Mas'ud Saleh
Mas'ud Saleh - avatar