I want to check if the password that is entered includes 1 uppercase letter, 2 lowercase letters, 3 digits, and 2 symbols, and only if those conditions are all met will the password be accepted.
What's wrong with my code? Everything I enter comes out false.
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
bool verify_password(char *p);
int main()
{
char p[] = "";
printf("Enter a password:\n");
scanf("%c",&p);
bool result = verify_password(p);
if (result)
printf("Verified password!\n");
else
printf("Invalid password!\n");
return 0;
}
bool verify_password(char *p)
{
int length = strlen(p);
if (length < 8) return false;
bool upper_count = false;
bool lower_count = false;
bool digit_count = false;
bool symbol_count = false;
for (int i = 0; i < length; i++)
{
if (isupper(p[i])) upper_count++;
if (islower(p[i])) lower_count++;
if (isdigit(p[i])) digit_count++;
if (ispunct(p[i])) symbol_count++;
}
if (upper_count > 1) return false;
if (lower_count > 2) return false;
if (digit_count > 3) return false;
if (symbol_count > 2) return false;
return true;
}