Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fullfil the requirements given in this question using C language.. And explain each line . Write a function min_add() to notify user about the minimum

Fullfil the requirements given in this question using C language.. And explain each line .

Write a function min_add() to notify user about the minimum number and type of characters that must be added to strengthen the password already entered by a user. Strong password rule are as follows: 1) Your password must be at least 8 characters in length. 2) Your password must contain at least one uppercase, or capital letter(ex: A, B, etc.) 3) Your password must contain at least two lowercase letter. 4) Your password must contain at least one number digit (ex: 0, 1, 2, 3, etc.) 5) Your password must contain at least one special character -for example: ~`!@#$%^&*()- _+={}[]|\;:",./?

Sol188:

Here is the code for the function min_add() that fulfills the given requirements:

#include

#include

#include

void min_add(char password[])

{

int length = strlen(password);

int required_length = 8 - length;

int upper_count = 0, lower_count = 0, digit_count = 0, special_count = 0;

for (int i = 0; i

{

if (isupper(password[i]))

{

upper_count++;

}

else if (islower(password[i]))

{

lower_count++;

}

else if (isdigit(password[i]))

{

digit_count++;

}

else if (ispunct(password[i]))

{

special_count++;

}

}

if (required_length = 1 && lower_count >= 2 && digit_count >= 1 && special_count >= 1)=>

{

printf("Your password is strong! ");

}

else

{

printf("Your password is weak. You need to add: ");

if (required_length > 0)

{

printf("%d more characters ", required_length);

}

if (upper_count

{

printf("at least one uppercase letter ");

}

if (lower_count

{

printf("at least two lowercase letters ");

}

if (digit_count

{

printf("at least one number digit ");

}

if (special_count

{

printf("at least one special character ");

}

}

}

Explanation:

  • The function min_add() takes a character array password as input.
  • It first finds the length of the password using the strlen() function and calculates the number of characters required to make the password at least 8 characters long.
  • It then checks the number of uppercase, lowercase, digit, and special characters in the password using the isupper(), islower(), isdigit(), and ispunct() functions, respectively.
  • Based on the counts of each type of character, it checks whether the password satisfies the strong password rules or not.
  • If the password is strong, it prints a message indicating the same.
  • If the password is weak, it prints a message indicating the minimum number and type of characters that need to be added to the password to make it strong.
  • The function uses printf() statements to display the messages to the user.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions