Advertisement
fahimkamal63

Password Checker

Dec 9th, 2019
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. //  Password Checker
  2. //  Date: 10.12.19
  3. #include<stdio.h>
  4. #include<ctype.h>
  5. //  ctype.h header file is used to use all the test functions
  6.  
  7. int main(){
  8.     printf("=====Welcome To Password Checker=====\n\n");
  9.     char password[20];
  10.     printf("Enter your password: ");
  11.     gets(password);
  12.     int strength = 0, length = 0, i;
  13.     int capital = 0, small = 0, special = 0, number = 0;
  14.  
  15.     for(i = 0; password[i] != '\0'; i++){
  16.         //  Check if character is lowercase
  17.         if(islower(password[i])){
  18.             small = 1;
  19.         }
  20.         //  Check if character is uppercase
  21.         else if(isupper(password[i])){
  22.             capital = 1;
  23.         }
  24.         //  Check if character is number
  25.         else if(isdigit(password[i])){
  26.             number = 1;
  27.         }
  28.         //  Check if character is any special character
  29.         else if(ispunct(password[i])){
  30.             special = 1;
  31.         }
  32.         length++;
  33.     }
  34.     if(capital) strength++;
  35.     if(small) strength++;
  36.     if(special) strength++;
  37.     if(number) strength++;
  38.     if(length >= 8) strength++;
  39.  
  40.     if(strength <= 3) printf("\nPassword is weak.\n");
  41.     else if(strength == 4) printf("\nPassword is medium.\n");
  42.     else if(strength == 5) printf("\nPassword is strong.\n");
  43. }
  44. //  Do a little bit of research on it.
  45. //  Still not clear then ask.
  46. //  Try not to memorize but to understand.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement