Develop a C++ program that simulates a user creating/entering a new password into a system.
You may presume that the username is irrelevant to complete this program.

Have the program ask the user to enter a proposed password as a string.

Validate that the password meets the following criteria:

Password must be at least ten characters long
Password must contain at least one uppercase letter
Password must contain at least one lowercase letter

Respuesta :

C++ program for Validating password

#include <iostream>

#include<cstring>

using namespace std;

int main()//driver function

{

char password[100];//declaring variables password

int lower=0,upper=0,flag=1;

cout<<"Enter the password\n";//taking input

cin>>password;

int length = strlen(password);//finding length

for(int i=0;i<length;i++)

{

if(password[i]>=65&&password[i]<=90)/*checking string must contain at least one uppercase letter */

{

upper=1;

}

if(password[i]>=97&&password[i]<=122)/*Checking string must contain at least one uppercase letter*/

{

lower=1;

}

}

if(length<10)//checking that string length should be less than 10

{

flag=0;

cout<<"Password must be at least ten characters long\n";

}

if(upper==0)

{

flag=0;

cout<<"Password have to be at least one uppercase letter\n";

}

if(lower==0)

{

flag=0;

cout<<"Password have to be at least one lowercase letter\n";    

}

if(flag==1)//if all condition turns out to true,printing Valid Password  

{

cout<<"Valid Password";

}

}

Output

Enter the password  

 Ayushyadav

  Valid Password

Enter the password  

  Ayush

Password must be at least ten characters long

 Enter the password

anmolyadav

Password have to be at least one uppercase letter

ANMOLVIJWANI

Password have to be at least one lowercase letter