Print Friendly and PDF

#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main()
{
char pass[20],pw[20]="password"; //you can change the password as well as the length of String..
int n,i=0;//counter
cout<<"Enter length of password : ";
cin>>n; /* taking input that how long you password is, so the following loop will iterate that number of times. */
cout<<"\nEnter Password : ";
for(i=0; i<n; i++)
{
pass[i]=getch(); //storing characters in String
cout<<"*";// displaying Asterisk(s)
}
pass[i]='\0'; /*delimiting the string with NULL Character..!!
this step is very important..!! if you don't delimit the string
with NULL character then you will not get the desired results
as the garbage value will also remain in there */
if(strcmp(pass,pw)==0) //checking the validity of entered password
cout<<"\n\nCorrect Password.\n\n";
else
cout<<"\n\nIncorrect Password.\n\n";
system("pause");
return 0;
}

zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: