password masking in c++
<p>I want to implement a login form in c++, so I wrote a function as follows:</p>

<pre><code>string setPass(bool show_asterisk = true)
{
    const char BACKSPACE = 8;//ASCII code for BACKSPACE Key
    const char ENTER = 13;//ASCII code for ENTER Key
    string pass = " ";//initialize string
    char c = ' ';//initialize character 

    while ((c = _getch()) != ENTER)
    {
        if (c == BACKSPACE)
        {
            if (pass.length() != 0)
            {
                if (show_asterisk)
                   cout &lt;&lt; "\b \b";
                pass.resize(pass.length() - 1); //resize the length of pass 
            }
        }
        else if (c == 0 || c == 224)//when player press esc key
        {
            _getch();
            continue;
        }
        else
        {
            pass.push_back(c);
            cout &lt;&lt; '*';
        }
    }
    cout &lt;&lt; endl;
    return pass;
}
</code></pre>

<p>Here is the code that executes the function:</p>

<pre><code>cout &lt;&lt; "==================" &lt;&lt; endl;
cout &lt;&lt; "      login       " &lt;&lt; endl;
cout &lt;&lt; "  ID:";
cin &gt;&gt; id;
cout &lt;&lt; "  Password:";
cin &gt;&gt; pwd;
pwd = setPass();
</code></pre>

<p>I compiled this code but it seems like the function didn't work, because the password is not being masked. Here's an image showing what happens:</p>

<p><a href="https://i.stack.imgur.com/r6SVX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r6SVX.png" alt="enter image description here"></a></p>

<p>I tried to fix the problem but I can't figure it out.</p>