samedi 27 juin 2015

Why is my password checking code not working correctly? It gives same output regardless of whatsoever input

I made a password checking program which checks for the following criteria:- Should have atleast 1 uppercase, 1 lower case, 1 special character, 1 number, lesser than 100 characters and thats it. I have not given any lower limit. And no matter what input I give(correct or incorrect), the program gives me the same or similar output as attached in my screenshot. I tried following inputs, for eg:- Pratik10, pratik10, pratikten, pr@tiK10 I get the same ouput "Password is fine and valid".

Why is my program not checking the defined conditions correctly? it is not even printing the counters of the password correctly.

Following is my code:

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

int main()
{
    char x[100];
    int i;
    int uc=0;
    int lc=0;
    int num=0;
    int misc=0;
    printf("enter your password\n");
    scanf("%s",x);
    for(i=0;i<100;i++)
    {
    if (isalpha(x[i]))
        {
    if (isupper(x[i])) {uc++;}
    if (islower(x[i])) {lc++;}
        }
    if (isdigit(x[i])) {num++;}
    else {misc++;}
    }
    printf("checking your password\n");
    printf("%d uc\n",uc);
    printf("%d lc\n",lc);
    printf("%d num\n",num);
    printf("%d misc\n",misc);
    if ((uc>0)&&(lc>0)&&(num>0)&&(misc>0))
    {
    printf("password is fine and valid\n");
    }
    else
    {
    if(lc<=0) {printf("lowercase character(s) missing cannot proceed without inclusion\n");}
    if(uc<=0) {printf("uppercase character(s) missing cannot proceed without inclusion\n");}
    if(num<=0) {printf("number(s) missing cannot proceed without inclusion\n");}
    if(misc<=0) {printf("special character(s) missing cannot proceed without inclusion\n");}
    printf("please include all the missing parameters in combination to validate the password and try again\n\n");
    }
return 0;
}

How to correct this? (attached is the screenshot of sample output)

enter image description here

Aucun commentaire:

Enregistrer un commentaire