Password validator | Sololearn: Learn to code for FREE!


Password validator

Can we create password validator in C, which has alphanumeric characters and atleast one special character without space???

7/24/2019 3:12:44 PM


2 Answers

New Answer


Why should that not be possible?


#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]=='$'||s[i]=='%'||s[i]=='&'||s[i]=='*'){ special_characters++; } } if(length>=7 && special_characters>=1 && numbers>=2){ printf("Strong"); } else { printf("Weak"); } } You can try this one..It will be valid if at least 1 special character, length>=7 and 2 or more numbers. You can modify this as you need.. .