Challenge #1 Answer

0 Pudge P-Pod · July 8, 2015
Not sure if this is the best way to solve this problem but it did work.
If anyone has some feedback on how I could do better please let me know.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char Password[20] = "                    ";
    int n, i, a, b, c, d;
    a = b = c = d = 0;
    printf("Please enter a password that is over 8 characters in length.\n");
    printf("The password must contain one of the following characters:\n");
    printf("!, @, #, $, or % %\n");
    printf("\n");
    printf("Enter Password here:");
    scanf("%s", Password);
    for(i=0; i<=21; i++){
        if(isalpha(Password)){
            a = 1;
               if(isupper(Password)){
                    b = 1;
               }
    }else if(isdigit(Password)){
        c = 1;
    }else if( Password == 36 ){
        d = 1;
    }
        if(a == 1 && b == 1 && c == 1 && d == 1){
            printf("\n");
            printf("Good job you have entered a valid password.\n");
            printf("\n");
            break;
        }
        }
    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
-1 c student · July 8, 2015
for %s, scanf inputs the string into the array and then appends a null terminator.  if i enter a password "ABC123!", the password array will be
[A][B][C][1][2][3][!][0][x][x] [x] [x] [x] [x] [x] [x] [x] [x] [x] [x]    // password array elements
[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16] [17][18][19]   // array elements

with your loop
for(i=0; i < = 21; i++)

what category does the null terminator fall under?  an alphanumeric character?  a digit?

also, what is at element 20 and 21?
0 Alexander Golovesov · July 8, 2015
Mine is "Simple enough :)"

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main(){

    char tuna[3];

    printf("Log in \n");
    scanf(" %s", tuna);

    if( (isupper(tuna[0])) || (isupper(tuna[1])) || (isupper(tuna[2])) ){

        if( (isdigit(tuna[0])) || (isdigit(tuna[1])) || (isdigit(tuna[2])) ){

            if( (tuna[0] == '$') || (tuna[1] == '$') || (tuna[2] == '$') ){
                printf("good password");
            }else{
                printf("bad password");

            }
        }else{
            printf("bad password");
        }

    }else{
        printf("bad password");
    }

    return 0;
}
0 Igor Dobovicek · July 9, 2015
Hi guys! I think I've solved it. Try this out and let me know if you think it's good. ;)


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{
    int i,upperCase,lowerCase,number,specChar;
    char password[20];

    do{
        printf("\nEnter your password. \n\nUse capital letter, a number and a special sign for good strength of password. \nUse 8 characters for password, precisely. \n\n");
        scanf(" %s", password);}while(strlen(password)!=8); // do this as long as the number of entered characters is not 8! while(strlen(password)!=8);
//strlen() defines a length of entered string (number of characters)

    printf("\nYour entered: %s \n\n", password);

    printf("Checking...\n\n");

    for(i=0; i<8; i++){ //loop 8 times through all 8 characters
        if(isalpha(password)){
            if(isupper(password)){
                printf("%c is an upper case letter. \n", password);
                upperCase=1;
            }else{
                printf("%c is a letter. \n", password);
                lowerCase=1;
                }
        }else{
            if(isdigit(password)){ //put password instead of password
                printf("%c is a number. \n", password);
                number=1;
            }else{
                printf("%c is a special character. \n", password);
                specChar=1;
            }
        }
    }

    if(upperCase==1 && lowerCase==1 && number==1 && specChar==1){
        printf("\nYour password is strong! Well done!\n\n");
    }else{printf("\nYour password is weak! Use all required symbols! \n\n");}

    return 0;
}

For some reason it does not display "password  square bracket  i  square bracket" instead of "password" so make the correction manually in the FOR block
0 Pudge P-Pod · July 11, 2015
Thank you for the feedback c student.   You are correct about the formatting of the for loop.  It should stop at 19 and not 21 because there is nothing after 19.  I will give it a try and let you know how it works.
  • 1

C

107,251 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator