0

Password Validation

Please solve this password validation from code coach in c.Thanks in advance. I have included everything but it is satisfying 7/13 tasks only. My code: #include <stdio.h> int main () { char a[100]; int l,countnum=0,countchar=0; scanf("%s",a); l=strlen(a); for(int i=0;i<l;i++) { if(a[i]=='!'||a[i]=='@'||a[i]=='#'||a[i]=='

#x27;||a[i]=='%'||a[i]=='&'||a[i]=='*') { countchar++; } if(a[i]==1||a[i]==2||a[i]==3||a[i]==4||a[i]==5||a[i]==6||a[i]==7||a[i]==8||a[i]==9||a[i]==0) countnum++; } if((countchar ==2)&&(countnum>=2)&&(l>=7)) printf("Strong"); else printf ("Weak"); return 0; }

25th Mar 2020, 7:13 PM
O.Naga Lakshmi Lalasa
O.Naga Lakshmi Lalasa - avatar
4 Answers
0
1 == '1' is false. You are comparing chars so a[i]=='1' || ... Also there can be more than 2 special chars in your password. Don't forget to link your code and to use relevant tags(like C, CodeCoach...) in future questions.
28th Mar 2020, 3:35 AM
Kevin ★
+ 3
Oh, you have to create a code from code playground, make it public, and then give us that link, for us to the see the code
25th Mar 2020, 8:17 PM
CeePlusPlus
CeePlusPlus - avatar
+ 1
Thanks a lot kevin :))
28th Mar 2020, 8:26 AM
O.Naga Lakshmi Lalasa
O.Naga Lakshmi Lalasa - avatar
0
#include <stdio.h> main() { char s[100]; scanf("%s",&s); int i,length ,numbers=0, special_characters=0; length=strlen(s); for(i=0;i<length;i++){ if(s[i]>='0'&&s[i]<='9'){ numbers++; } else if(s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='
#x27;||s[i]=='%'||s[i]=='&'||s[i]=='*'){ special_characters++; } } if(length>=7 && special_characters>=2 && numbers>=2){ printf("Strong"); } else { printf("Weak"); } } You can try this one.. .
2nd May 2020, 6:17 AM
View My Project
View My Project - avatar