Challenge #1..help!

+1 Dong-Min Kim · May 4, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>


int main()
{
    char pass[20];
    int upper, lower, digit, dollar, i;

    printf("Insert a password:\n");
    printf("(Don't forget an uppercase and lowercase letter, a number, and a dollar sign!) \n");
    scanf("%s", &pass);

    for( i=0; i<=20; i++){
       if( isalpha(pass) ){
  if( isupper(pass) ){
              upper+=1;
  }else{
              lower+=1;
           }
       }else{
  if( isdigit(pass) ){
              digit+=1;
  }else{
              dollar+=1;
           }
       }        

    }
    if( upper>=1 && lower>=1 && digit>=1 && dollar>=1 ){
        printf("Great password!");
    }else{
        printf("Sucks...try again");
    }

    return 0;


}

Post a Reply

Replies

Oldest  Newest  Rating
0 Onkar Mumbrekar · May 4, 2015

#include
#include
#include
#include
#include
#include


void main()
{
char pass[20];
int upper=0,lower=0,digit=0,dollar=0, i;
clrscr();
printf("Insert a password:\n");
printf("(Don't forget an uppercase and lowercase letter, a number, and a dollar sign!) \n");
scanf("%s", &pass);

for( i=0; i=1 && lower>=1 && digit>=1 && dollar>=1 )
{
  printf("Great password!");
}
else
{
  printf("Sucks...try again");
}

getch();
}
0 Onkar Mumbrekar · May 4, 2015
http://txt.do/ximx
+1 Stefanos Keh · May 7, 2015
Hey! I was wondering if someone can comment on my solution. Am I using too many if statements? Is Onkar's solution better?

http://textuploader.com/g7h7

Note that I have simplified the password requirements compared to the ones asked in the youtube video.
0 Akash Kamat · May 12, 2015
#include<stdio.h>
#include<string.h>
int main()
{
    char pass[20];
    printf("Enter your password : \n");
    printf("Please note that your password must contain at least 1 uppercase and 1 lowercase letter, a number and a $ symbol.\n");
    scanf(" %s", &pass);

    int u,l,n,s;
    u=l=n=s=0;
    int i,j;

    for(i=0;i<strlen(pass);i++){
        if(isalpha(pass)){
            if(isupper(pass)){
                u++;
            }else{
                l++;
            }
        }else if(isdigit(pass)){
            n++;
        }else if(pass=='$'){
            s++;
        }
    }

    if(u>0 && l>0 && n>0 && s>0){
        printf("Your password is strong.");
    }else{
        printf("Please enter another password.");
    }


    return 0;
}
0 Harshad Lele · May 14, 2015
Guys this is how I wrote it -

Have a look at it - 

// Program for checking whether password contains Uppercase Letter, Number and $

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

int main()
{
    char password [20];
    int i=0,a=0,b=0,c=0;

    printf("Enter your password : ");
    scanf( "%s" , &password);

    for (i= 0 ; i < strlen(password); i++ )
    {
        if  ( isupper(password) )
                a=1;
        else if ( isdigit(password) )
                b=1;
        else if ( password== '$' )
                c =1;
    }
        if (a == 1 && b == 1 && c == 1)
        printf("Your password is Good");
        else
        printf("your password sucks");

     return 0;
}
0 Onkar Mumbrekar · May 14, 2015
with some other modifications......

http://textuploader.com/f0fs
  • 1

C

107,182 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator