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