Advertisement
ssoni

password.c

Jan 27th, 2022
1,681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6.  
  7. int main(void)
  8. {
  9.     //Enter password
  10.     string pw;
  11.     pw = get_string("Enter password: ");
  12.  
  13.     int hasUpper=0;
  14.     int hasLower=0;
  15.     int hasSymbol=0;
  16.     int hasDigit=0;
  17.     int score=0;
  18.  
  19.     //loop thru the password (upper, lower, digit, symbol, LENGTH)
  20.     for (int i=0; i<strlen(pw); i++)
  21.     {
  22.         if (isupper(pw[i]) != 0)
  23.         {
  24.             hasUpper=1;
  25.         }
  26.         else if (islower(pw[i]) != 0)
  27.         {
  28.             hasLower=1;
  29.         }
  30.         else if(pw[i] >= 48 && pw[i] <= 57)
  31.         {
  32.             hasDigit=1;
  33.         }
  34.         //    ((33-47) or (58-64) or (91-96))
  35.         else if((pw[i] >= 33 && pw[i] <= 47) || (pw[i] >= 58 && pw[i] <= 64) || (pw[i] >= 91 && pw[i] <= 96))
  36.         {
  37.             hasSymbol=1;
  38.         }
  39.  
  40.     }
  41.  
  42.     //calc score
  43.     int base;
  44.  
  45.     //add 1 to base to ensure base is at least 2
  46.     base = 1 + hasUpper + hasLower + hasDigit + hasSymbol;
  47.  
  48.     //print result
  49.     //score = base ^ length
  50.     score = pow(base, strlen(pw));
  51.     printf("Score = %i\n", score);
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement