A password is good if it has at least one digit,one alphanumeric charecter, one uppercase letter, one ordinary lowercase letter letter and consists of 8 charecters or more. I created this program, but I'm not getting correct results.. What is the problem?

void main()
{
cout<<"This program checks whether the password entered by the user is good or not"<<endl;
cout<<"Enter the password"<<endl;
char password[100];
int atleastoneDigit=0,atleastoneLowercaseletter=0,atleastoneUppercaseletter=0,atleastonealphanumericCharecter=0;
cin>>password;
int length=strlen(password);
for(int i=0;i<length;i++)
{
if(password[i]>=33&&password[i]<=58)//ASCII values for uppercase letters
atleastoneUppercaseletter++;

else if(password[i]>=65&&password[i]<=90)
        atleastoneLowercaseletter++;
else if(password[i]>=16&&password[i]<=25)
    atleastoneDigit++;
else
atleastonealphanumericCharecter++;

}

    if(length>=8&&atleastoneDigit!=0&&atleastoneUppercaseletter!=0&&atleastoneLowercaseletter!=0&&atleastonealphanumericCharecter!=0)
        cout<<"This is a good password!"<<endl;
    else
        cout<<"This is not a good password!"<<endl;

}

what if you check it this way..

hasAlpha...hasLower are boolean
pw is string...

for(int i=0; i<pw.length(); i++){
    if(isalpha(pw[i]))
        hasAlpha = true;
    if(isdigit(pw[i]))
        hasDigit=true;
    if(isupper(pw[i]))
        hasUpper =true;
    if(islower(pw[i]))
        hasLower = true;
    }

Check your ascii values.
Digits are decimal 48 to 57.
If the password contains alpha characters (a->z, A->Z)and numeric(0->9) characters it is then refered to as alphanumeric.

Cheers
Milton

Expanding on MNeal's post, stop using magic numbers. If you want to test for the character 'A', use 'A', not 65. Zero is '0', not 48.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.