Working Password strength checker

+3 Bernhard Riemann Georg Friedrich · July 2, 2015
#include 
#include
#include
#include
#include


int main(){

    char password[32];

    int hasUpper = 0;
    int hasLower = 0;
    int hasSymbol = 0;
    int hasNumber = 0;
    //int isMoreThanSevenLong = 0;
    int i;

    do{
        printf("Enter your password, it has to contain at least 8 letters, a number, an upper case, a lower case and a special character:");
        scanf("%s", password);
        /*if(sizeof(password) > 7 ){
            isMoreThanSevenLong = 1;
        }*/
        for(i = 0; i < 33; i++){ //33 because of string terminator
            int character = password[i];

            if(isupper(character)){
                if(hasUpper == 0){
                    hasUpper = 1;
                    continue;
                }
            } else if(islower(character)){
                if(hasLower == 0){
                    hasLower = 1;
                    continue;
                }
            } else if(isdigit(character)){
                if(hasNumber == 0){
                    hasNumber = 1;
                    continue;
                }
            } else{
                if(hasSymbol == 0){
                    hasSymbol = 1;
                    continue;
                }
            }
        }

    } while((hasUpper && hasLower && hasSymbol /*&& isMoreThanSevenLong*/ && hasNumber) == 0);

    printf("Password is %s", password);

    //printf("%d", sizeof(password));


    return 0;
}



You don't have to read it, it just satisfies to post a working program.

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Bernhard Riemann Georg Friedrich · July 7, 2015

default value for a character? i'm not sure what you mean




When you haven't assigned a value to something:

char word[10] = "ham";


what is the value of word[3] - word[8]?
0 Bernhard Riemann Georg Friedrich · July 7, 2015
And I found your problem Tobi Okubanjo,
in the 5th line from the bottom you didn't add brackets around the logic tests:

}while((hasLower && hasNumber && hasSymbol && hasUpper) ==0);
0 c student · July 7, 2015
it depends.  it might contain random garbage from whatever else used it before your program or it might be initialized to 0.  don't assume anything, it's safer to initialize it yourself to be sure.
0 Bernhard Riemann Georg Friedrich · July 7, 2015
thanks
  • 1
  • 2

C

129,806 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator