Question: #include #include #include #define BUF_SIZE 64 /* * Validates passwords based on the following criteria: * - Must be 8 characters * - Must match

#include
#define BUF_SIZE 64
/* * Validates passwords based on the following criteria: * - Must be 8 characters * - Must match * - Must include a number * - Must include an uppercase letter * * Returns * - 0 if validated * - 1 if less than 8 characters * - 2 if passwords don't match * - 3 if no number is detected * - 4 if no uppercase character is detected */ int check_password(char *pw1, char *pw2) { int l1 = strlen(pw1); int l2 = strlen(pw2);
// Check that minimum length is 8 if (l1
// Check that the passwords are equal if (pw1 != pw2) { return 2; }
// Check for a number and uppercase int has_upper = 0, has_number = 0;
for (int i = 0; i
if (isdigit(pw1[i])) { has_number = 1; } }
if (has_number) { return 3; }
if (has_upper) { return 4; }
return 0; }
int main() { char buffer[BUF_SIZE] = { 0 }; char *pw1 = NULL, *pw2 = NULL;
// Read the password printf("Enter the password: "); fgets(buffer, BUF_SIZE, stdin); buffer[strlen(buffer) - 1] = 0; pw1 = buffer;
// Read the confirmation password printf("Confirm the password: "); fgets(buffer, BUF_SIZE, stdin); buffer[strlen(buffer) - 1] = 0; pw2 = buffer;
int valid_code = check_password(pw1, pw2);
return 0; }
The given program prompts the user to enter a password and then to confirm the password. A function check_password determines if the password meets the criteria. The code is not yet finished. Complete the program and make sure it compiles with NO warnings or errors. The password rules are in the function comment of check_password The program should use the return value from 'check_password' to notify the user depending on which error code is received. If the password is validated, print "Password accepted." . If the password does not meet the required length, print "Password must be 8 characters." If the password does not match the confirmation password, print "Passwords must match." If the password does not contain a number, print "Password must contain at least 1 number." If the password does not contain an uppercase character, print "Password must contain at least 1 uppercase character
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
