Problem Description: 1.Some Websites impose certain rules for passwords. Write a
ID: 3626300 • Letter: P
Question
Problem Description:
1.Some Websites impose certain rules for passwords. Write a program and method that checks whether a string is a valid password. Suppose the password rule is as follows:
A password must have at least eight characters.
A password consists of only letters and digits.
A password must contain at least two digits.
Write a program that prompts the user to enter a password and displays "valid password" if the rule is followed or "invalid password" otherwise.
Sample 1
Enter a string for password: wewew43x
valid password
Sample 2
Enter a string for password: 343a
invalid password
Analysis:
(Describe the problem including input and output in your own words using Comment.)
Design:
(Describe the major steps for solving the problem Using Comment.)
Testing: (Describe how you test this program using Comment)
Explanation / Answer
#include< stdio.h >
void main()
{
char password[10];
int length;
int digit=0; //inputting password
printf("Enter a string for password:");
gets(password);
length=strlen(password);
{
if(isdigit(password[i]))
digit++;
}
printf("Invalid password Atleast 8 characters !!");
else if(digit < 2)
printf("Password should contain alteast one digit");
else
printf("Valid password");
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.