Hiding User Input

Hey I have a project where I need a user to enter a password.
I had saw this post, and It seems to work. However, There is a problem. I was hoping that every character the user enters would appear to be an asterisk but this code Im using seems to hide it completely. The source is line for line from this forum post

http://www.cplusplus.com/forum/beginner/43683/

Can I modify that to get the kind of functionality I'm talking about?

Here's my source:
1
2
3
4
5
6
7
8
9
10
11
12
13
/** A private method used to mask user input.   */
string Password::getInput()
{
    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    DWORD mode = 0;
    GetConsoleMode(hStdin, &mode);
    SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));

    string s;
    getline(cin, s);
    SetConsoleMode(hStdin, mode);
    return s;
}
Last edited on
That is actually the correct way to do it.

Unfortunately, people want asterisks/bullets/etc (probably to shoot their program...)
http://www.cplusplus.com/forum/general/3570/#msg15410

Hope this helps.
Topic archived. No new replies allowed.