Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- /*Password Verification Program tests for 8 to 10 characters, and at least
- *1 upper case letter, 1 lower case letter, 1 digit, 1 '$' punctuation*/
- int main()
- {
- char userName[50];
- char firstPassword[100];
- char password[100];
- int a = 0;
- int upper = 0, lower = 0, digit = 0, dollarSign = 0;
- printf("Please Create A Username Without Spaces.\n\nNext Create A Password"
- "Between 8 & 10 Characters In Length.\nThe Password Must Include "
- "At Least One Upper Case Letter,\nOne Lower Case Letter, One Digit,"
- "and the '$' Punctuation.\n\n\n");
- printf("Enter Username: ");
- scanf(" %s", userName);
- //Prompts for firstPassword & password then compares strings until they match
- do {
- printf("\nEnter Password: ");
- scanf(" %s", firstPassword);
- printf("Confirm Password: ");
- scanf(" %s", password);
- if(strcmp(firstPassword, password) != 0)
- printf("\nPasswords Do Not Match, Try Again.\n\n");
- }while(strcmp(firstPassword, password) != 0);
- //Tests for Upper/Lower/Digit/'$' and adds 1 to respective int variables
- while(a <= 10){
- if(isupper(password[a])) {
- upper = 1;
- }
- if(islower(password[a])) {
- lower = 1;
- }
- if(isdigit(password[a])) {
- digit = 1;
- }
- if((password[a] == '$')) {
- dollarSign = 1;
- }
- a++;
- }
- /*Test password length 8 to 10 characters
- *Nested If-else tests for password requirements*/
- if (strlen(password) >= 8 && strlen(password) <= 10){
- if(upper && lower && digit && dollarSign){
- printf("\nCongratulations %s Your Password Is Set.\n", userName);
- }
- else{
- printf("\nTry Again, Your Password Needs At Least 1 Upper/Lower/Digit/'$':\n");
- }
- }
- //Test password length - too long/short
- if(strlen(password) >= 11){
- printf("\nPassword Is Too Long. Maximum 10 Characters In Length. Try Again.\n\n");
- }
- if(strlen(password) <= 7){
- printf("\nPassword Is Too Short. Minimum 8 Characters In Length. Try Again.\n\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement