password

PHOTO EMBED

Sun May 26 2024 06:45:25 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

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

enum Password_Strength
{
    TOO_WEAK,
    STRONG_ENOUGH
};

enum Password_Strength is_secure_password(char* password);

int main(void)
{
    char test_password[32];
 
    do
    {
        printf("Choose a password: \n");
        scanf("%31s", test_password);
    }
    while (is_secure_password(test_password) == TOO_WEAK);
 
    printf("%s is secure enough!\n", test_password);
 
    return 0;
}

    int is_upper(char ch)
{
    return (ch >= 'A' && ch <= 'Z');
}

int is_lower(char ch)
{
    return (ch >= 'a' && ch <= 'z');
}

int is_digit(char ch)
{
    return (ch >= '0' && ch <= '9');
}
enum Password_Strength is_secure_password(char* password)
{
    int length = strlen(password);
    int upper_count = 0;
    int lower_count = 0;
    int digit_count = 0;

    if (length < 8 || length > 12) // Minimum length requirement
    {
        return TOO_WEAK;
    }



    for (int i = 0; i < length; i++)
    {
        if (is_upper(password[i]))
            upper_count++;
        else if (is_lower(password[i]))
            lower_count++;
        else if (is_digit(password[i]))
            digit_count++;
    }

    if (upper_count >= 2 && lower_count >= 2 && digit_count >= 1)
    {
        return STRONG_ENOUGH;
    }
    else
    {
        return TOO_WEAK;
    }
 

}
content_copyCOPY

For example: Input Result hi hello Hello Hello*34 HellO*34 Choose a password: Choose a password: Choose a password: Choose a password: Choose a password: HellO*34 is secure enough! The goal of this exercise is to familiarize students with implementing functions that evaluate password strength according to specified rules. The exercise involves the implementation of a function called is_secure_password in C, which will evaluate if a given password meets certain criteria. Requirements Function Declaration and Definition Implement the function is_secure_password that takes a single parameter: A pointer to a null-terminated character array (the password). The function should return an enumerated value: TOO_WEAK if the password is not strong enough. STRONG_ENOUGH if the password meets all the required conditions. Password Strength Rules The program should evaluate the password based on the following rules: Password must contain at least two lowercase characters. Password must contain at least two uppercase characters. Password must contain at least one digit. Password must be at least 8 characters long. Password must not be more than 12 characters long. Main Function The main() function already provides a do-while loop where the user is asked to choose a password until a strong enough password is entered. When the entered password is strong enough, a message should be displayed to indicate that the password is secure.