Challenge 1

+1 Homer Simpson · November 1, 2014
#include <stdlib.h>
#include <stdio.h>

/*
A program that tests to see if a user entered a strong password.
(Contains uppercase letter, number, and symbol)

*/
int main()
{

    int i, digit = 0, upperCase = 0, symbol = 0;
    char password[20];

    printf("Enter in a password.\nMust contain a numeric value, upper case letter, and a symbol.\n");
    scanf("%s", password);

    // Loops through the password checking each char one at a time
    for(i = 0; i < 20; i++) {
        // if the char is a letter it checks to see if its uppercase
        if(isalpha(password)){
            if(isupper(password))
                upperCase++;
            // if not it checks to see if its a digit
            } else {
                if(isdigit(password))
                    digit++;
            // if its not a number or a letter it must be a symbol
                else
                    symbol++;
            }
    }

    // outputs whether or not the password was valid
    if(digit > 0 && upperCase > 0 && symbol > 0)
        puts("\nPassword is valid.\n");
    else
        puts("\nYour password sucks.\n");

    return 0;
}



Woohoo!
/images/forum/upload/2014-11-01/5e7525df565615cd422e2b16ee3e628b.jpg

Post a Reply

Replies

Oldest  Newest  Rating
+1 Daniel Vladimirov · November 1, 2014
Hey, Homer,
Did you try to check a program without symbols? Because if you haven't noticed the program that you've created counts the unused characters of the array as symbols too and if only a symbol is missing it still accepts the password.
0 Homer Simpson · November 1, 2014
Tarter sauce, no I hadn't tested for that! Thank you for pointing that out. :D +1 I'll work on it again and see if I can fix that.
  • 1

C

107,105 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator