Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. //password challenge
  7. int main()
  8. {
  9.     char myPassword[50];
  10.  
  11.     //grab password
  12.     //todo Why the fuck teach people to get BOFd by default?
  13.     printf("Please input your password!\n");
  14.     fgets(myPassword, 50, stdin);
  15.     // printf("pass: %s\n", myPassword);
  16.  
  17.     //check size
  18.     size_t arrayLength = strlen(myPassword);
  19.     // printf("length: %ld\n", arrayLength);
  20.    
  21.     //requirements
  22.     int upper = 0;
  23.     int lower = 0;
  24.     int cashSymbol = 0;
  25.     for(int i = 0; i < arrayLength; i++){
  26.         //printf("char: %c\n", myPassword[i]);
  27.         if (upper == 0 || lower == 0 || cashSymbol == 0){
  28.             if ( isupper(myPassword[i]) ){
  29.                 upper += 1;
  30. //      printf("Found upper!");
  31.   }
  32.             else if ( myPassword[i] == '$' ) {
  33.                 cashSymbol += 1;
  34. //      printf("Found $ symbol!");
  35.             }
  36.             else if ( islower(myPassword[i])){
  37.                 lower += 1;
  38. //      printf("Found lower!");
  39.             }
  40.         } else {
  41.             printf("Upper, lower, and special symbol located. Great password.\n");
  42.             return 0;
  43.         }
  44.     }
  45.     if (upper == 0 || lower == 0 || cashSymbol == 0){
  46.         printf("Did not find an upper, lower, and cash symbol in the password.\n");
  47.         return 1;
  48.     }
  49.     printf("Upper, lower, and special symbol located. Great password.\n");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement