Advertisement
Red_Man

Bucky's C Challenge #1

Mar 1st, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6. /*Password Verification Program tests for 8 to 10 characters, and at least
  7.  *1 upper case letter, 1 lower case letter, 1 digit, 1 '$' punctuation*/
  8.  
  9. int main()
  10. {
  11.     char userName[50];
  12.     char firstPassword[100];
  13.     char password[100];
  14.     int a = 0;
  15.     int upper = 0, lower = 0, digit = 0, dollarSign = 0;
  16.  
  17.     printf("Please Create A Username Without Spaces.\n\nNext Create A Password"
  18.            "Between 8 & 10 Characters In Length.\nThe Password Must Include "
  19.            "At Least One Upper Case Letter,\nOne Lower Case Letter, One Digit,"
  20.            "and the '$' Punctuation.\n\n\n");
  21.  
  22.     printf("Enter Username:    ");
  23.     scanf(" %s", userName);
  24.  
  25. //Prompts for firstPassword & password then compares strings until they match
  26.     do {
  27.         printf("\nEnter Password:    ");
  28.         scanf(" %s", firstPassword);
  29.         printf("Confirm Password:  ");
  30.         scanf(" %s", password);
  31.  
  32.         if(strcmp(firstPassword, password) != 0)
  33.             printf("\nPasswords Do Not Match, Try Again.\n\n");
  34.     }while(strcmp(firstPassword, password) != 0);
  35.  
  36. //Tests for Upper/Lower/Digit/'$' and adds 1 to respective int variables
  37.     while(a <= 10){
  38.     if(isupper(password[a])) {
  39.         upper = 1;
  40.     }
  41.     if(islower(password[a])) {
  42.         lower = 1;
  43.     }
  44.     if(isdigit(password[a])) {
  45.         digit = 1;
  46.     }
  47.     if((password[a] == '$')) {
  48.         dollarSign = 1;
  49.     }
  50.     a++;
  51.     }
  52.  
  53. /*Test password length 8 to 10 characters
  54.  *Nested If-else tests for password requirements*/
  55.     if (strlen(password) >= 8 && strlen(password) <= 10){
  56.         if(upper && lower && digit && dollarSign){
  57.             printf("\nCongratulations %s Your Password Is Set.\n", userName);
  58.         }
  59.     else{
  60.         printf("\nTry Again, Your Password Needs At Least 1 Upper/Lower/Digit/'$':\n");
  61.     }
  62.     }
  63. //Test password length - too long/short
  64.     if(strlen(password) >= 11){
  65.         printf("\nPassword Is Too Long. Maximum 10 Characters In Length. Try Again.\n\n");
  66.     }
  67.     if(strlen(password) <= 7){
  68.         printf("\nPassword Is Too Short. Minimum 8 Characters In Length. Try Again.\n\n");
  69.     }
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement