PROGRAM TO MASK THE PASSWORD WITH * IN C++ WITH 3 CHANCES ONLY

//Example of password masking in CPP with * sign with 3 chances

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
char pwd[]="password", verify[20], ch;
int i, chance=0;
start:                 //label defined 
clrscr();
i=0;

cout<<"Enter the password to verify: ";
do
{
ch=getch();
if(ch!=13)
{
verify[i++]=ch;
cout<<"*";
}
else
{
verify[i++]='\0';
}
}while(ch!=13);

if(strcmp(pwd,verify)==0)
{
cout<<"\nPassword Matched...";
cout<<"\nWelcome User....";
}
else
{
cout<<"\nPassword Wrong....\n";
cout<<chance<<" used of 3 chances...";
cout<<"\nEnter the correct credentials";
chance++;
getch();
if(chance<=3) goto start;
}
getch();
}
Powered by Blogger.