Hi guys I just developing a system for my project and i want to mask the password when you input it.That is displaying "*" sings instead of text. The following is my code.
_getch() returns the character when a key is pressed, so you could do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <string>
#include <conio.h>
usingnamespace std;
char c;
string password;
// loop condition: get a character, while it isn't a newline (end of password), then...
while ((c=_getch()) != '\n')
{
// put it onto the back of the password
password.push_back(c);
// output a '*' character
_putch('*');
}
_getch() will return when a key is pressed by nothing will happen on the screen - so the user won't see anything.
When _getch() returns, if you output a '*' to the screen (_putch()), what the user will see is a key being pressed and a '*' appearing onscreen - so if you typed
If you want that there be a facility to change the password at runtime, then use file-handling. Save the desired password in a .dat or .txt file and write a function to truncate the fle and enter the new password.