Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that validates passwords according to the following rules: 1. Th

ID: 3531515 • Letter: W

Question

Write a program that validates passwords according to the following rules:


1. The password must be at least 8 characters and no more than 20.

2. The password must contain at least one upper-case letter, at least one lower-case letter, and at least one digit.

3. It must contain at least one character from the set ~!@#$%^&*()_+=-[]{};':",.?><


The program must request a password from the user and display whether it is valid or not. If it is not, show the rules and try again. If it is, let them validate another password.


The program terminates when the single character * is entered

Explanation / Answer

#include<iostream>


using namespace std;

int verifyPassword(char password[30])

{

int i;

char ch;

for( i=0;password[i];i++);

char special[30]={'~' , '!' , '@' , '#' , '$' , '%' , '^' , '&' , '*' ,'(',')' , '_' , '+' , '=' ,'-' ,'[',']' ,'{','}' ,';'

, ':' , '"' ,',','.','?','>','<',''};

if((i<6)&&(i>20))

return 0;

bool flag1=false;

bool flag2=false;

bool flag3=false;

for(int i=0;password[i];i++)

{

ch=password[i];

if((ch>='a')&&(ch<='z'))

flag1=true;

if((ch>='A')&&(ch<='Z'))

flag2=true;

for(int j=0;special[j]!='';j++)

if(ch==special[j])

flag3=true;


}

if(flag1&&flag2&&flag3)

return 1;

else

return 0;



}


int main()

{

char password[30];

char choice;

do

{

cout<<"enter a password that must have ";

cout<<"1. at least 8 charchters and max_imum 20 ";

cout<<"2 one upper-case letter ";

cout<<"3 one lower-case letter ";

cout<<"4. at least one character from the set ~!@#$%^&*()_+=-[]{};':"",.?>< ";

cin>>password;


if(verifyPassword(password))

{

cout<<" your password is valid ";

cout<<" select one of the option ";

cout<<" C .continue ";

cout<<" E.Exit ";

cin>>choice;

}

else

{

cout<<" your password is invalid ";

choice='C';

}

}while(choice!='E');

return 0;



}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote