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 1
Oldest  Newest  Rating
+1 Aju Antony · July 2, 2015
awesome job bro :D
0 Bernhard Riemann Georg Friedrich · July 6, 2015
Oh yeah. I was gonna make that changeable for the user, but noticed that it's useless, so I forgot that code there. Thanks for pointing it out. Would you know what the default value of a character in a character array is?
0 c student · July 6, 2015
default value for a character?  i'm not sure what you mean
0 peymans johans · July 6, 2015
http://www.gowebsite.ir
0 Tobi Okubanjo · July 6, 2015
I'm not sure how this is actually checking the password all this is doing is printing out the password.
I had the same idea as you did the moment bucky told me about the challenge but mine doesn't seem to be functioning properly can you take a look at it and help me out. 


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
int main()
{
    char Password[30];

    int hasUpper =0;
    int hasLower =0;
    int hasSymbol =0;
    int hasNumber =0;

        do{
            printf("Enter a password with a number, Uppper and lower case letters and a $ symbol.Make sure the number comes first.");
            scanf(" %s", &Password);

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

        printf("Your password is %s", Password);
    return 0;
}
0 mahdipedram60 mahdi · April 23, 2017
Thanks a lot.  have this problem in my blog:http://seocando.ir
0 طراحی سایت و سئو Azarinweb · December 22, 2016
Thank you so much, you just solved my problem. i have this problem in my blog: https://seofox.ir
0 Tobi Okubanjo · July 11, 2015
Thanks a lot. I see now why it's not working. You were a great help. I really appreciate it. 
0 Gitesh Khanna · July 7, 2015
is it actually working? i tried it and it allows me to keep the password even if i miss one condition of them all. 
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
  • 2

C

124,760 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator