+ 3

Password validation

I tried to solve this.. I got all the 9 conditions correct but the last 4 were wrong. Somebody help me!! p=input("") #string input count=0 special=['!', '@', '#', '

#x27;, '%', '&', '*'] a=0 d=0 sl=0 for i in range(len(p)): if(p[i].isalpha()): a=a+1 elif(p[i].isdigit()): d=d+1 elif (p[i] in special): sl=sl+1; count=a+d+sl if(count>=11 and sl>=2 and d>=2 and a>=7): print("Strong") else: print("Weak") This is my code in python.☝☝ And the below one is in C 👇👇. include <stdlib.h> #include <stdio.h> #include <string.h> main() { char l[1000]; int i,v,a=0,d=0,s=0,count=0; //printf("\n enter passeord:"); gets (l); for(i=0;i<strlen(l);i++) { if(l[i]=='!'|| l[i]=='@'|| l[i]=='#'||l[i]=='
#x27;|| l[i]=='%'|| l[i]=='&' ||l[i]=='*') s++; else if((l[i]>='A'&&l[i]<='Z')|| (l[i]>='a'&&l[i]<='z')) a++; else if(isdigit(l[i])) d++; } if(d>=2 && s>=2 && a>=7) printf("Strong"); else printf("Weak"); return 0; }

19th Mar 2021, 1:43 PM
nivedha srinivasan
nivedha srinivasan - avatar
10 Respostas
19th Mar 2021, 3:04 PM
Ervis Meta
Ervis Meta - avatar
+ 5
This will help you if you like this to analyze https://code.sololearn.com/cOjvkbJvYPg2/?ref=app
19th Mar 2021, 1:58 PM
JaScript
JaScript - avatar
+ 3
# Python code: a, b, c = input(), 0, 0 for x in a: if x.isnumeric(): b += 1 if x in "!@#$%&*": c += 1 if b > 1 and c > 1 and len(a) > 6: print("Strong") else: print("Weak") # Hope this helps
20th Mar 2021, 4:18 PM
Calvin Thomas
Calvin Thomas - avatar
+ 2
What is need of condition count>=11 in if block..? May i know about the logic? edit: nivedha srinivasan you are counting alphabets into variable 'a' but you need length of input string which also includes special chars and digits.. so take a = len(p) next only need special chars and digits separately.. in c : a = strlen(l); hope it helps you..
19th Mar 2021, 1:58 PM
Jayakrishna 🇼🇳
+ 1
In first, I understand more python than c so my comment will be for the python code. Firstly you don't need to check if in password given are characters cause this is not a criteria of the challenge. Secondly there are three cases you should check : 1-The length of password. 2-At least two numbers. 3-At least two special characters. So in python you may create three different functions to check those points or you just can run the check in a single for loop. For 2 and 3 you may need a variable to store the count of them. For the 1 just use len() function. For example: #this is without functions pass = str(input()) nums = list(range(10)) special_c = [#special characters needed] n = 0 s = 0 for char in pass: if char in nums: n++ elif char in special_c: s++ #the final check if len(pass)>=7 and n>=2 and s>=2: print('Strong') else: print('Weak') You got it ?😀
19th Mar 2021, 2:07 PM
Ervis Meta
Ervis Meta - avatar
+ 1
The same for the c code
19th Mar 2021, 2:09 PM
Ervis Meta
Ervis Meta - avatar
+ 1
Thank you ,guys.completed đŸ„łđŸ„ł
19th Mar 2021, 3:05 PM
nivedha srinivasan
nivedha srinivasan - avatar
+ 1
No problem 👍. Ask anytime
19th Mar 2021, 3:06 PM
Ervis Meta
Ervis Meta - avatar
+ 1
// C code: #include <stdio.h> int main() { char a[25]; char b[7] = {'!','@','#','
#x27;,'&','*','%'}; fgets(a, 25, stdin); int x=0, y=0, i; for (i=0;a[i]!='\0';i++) { for (int k=0;k<10;k++) { if (k == a[i] - 48) x++; if (a[i] == b[k * (k < 7)]) y++; } } if (x > 1 && y > 1 && i > 6) { puts("Strong"); } else puts("Weak"); } // Hope this helps
20th Mar 2021, 4:21 PM
Calvin Thomas
Calvin Thomas - avatar
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:13 PM
Mas'ud Saleh
Mas'ud Saleh - avatar