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 c student · July 3, 2015
if(sizeof(password) > 7 )

checks if the size of the password variable is greater than 7 and since you've defined it as having a size of 32, it will always be true.
+1 Aju Antony · July 2, 2015
awesome job bro :D
  • 1
  • 2

C

107,149 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator