Password in a c++ program
March 15, 2009 at 9:22 am | In Ultimate Concepts-C++/C | Leave a CommentTags: how to add password in a program?, Password in a c++ program, password in c program
Many of us keep want this ultimate solution, “that how can we add provide a password facility in a c++ or c program?”. Yes password facility such that if user enter “UltimatePedia” as his password then it should be displayed over the screen something like-”*************”. So here i give you the solution of this query (asked to me by many of you through mails):-
#include<iostream.h> //Header file for cout and cin.
#include<conio.h> //Header file for clrscr().
void main()
{ clrscr(); //To clear off the screen.
char psw[20]; //Size of the password.
char psw2=13; //Basically here 13 is the ASCII value for the “Enter”.
int i=-1;
cout<<”Enter your Password:”;
do{ i++;
psw[i]=getch();
cout<<”*”; //Displays “*” instead of the characters entered by the user.
}while(psw[i]!=psw2); //This loop runs untill user press enter or character limit for password is reached.
cout<<”ntPassword is accepted. Your password is:”<<psw; //Optional facility which displays the password as entered by the user. Note that it does not show the password in the “*” form.
getch(); //Termination of the program.
}
Now do i hope you can modify this program according to your need in a program. And if you still have any queries related to its working then do ask me.
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.










