this is getPassword function, and problem is exactly because of it.
How should I solve it?
Code:
string getPassword()
{
string result;
// Set the console mode to no-echo, not-line-buffered input
DWORD count;
HANDLE ih = GetStdHandle(STD_INPUT_HANDLE);
HANDLE oh = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(ih, ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
// Get the password string
char c;
while (ReadConsoleA(ih, &c, 1, &count, NULL) && (c != '\r') && (c != '\n'))
{
if (c == '\b')
{
if (result.length())
{
WriteConsoleA(oh, "\b \b", 3, &count, NULL);
result.erase(result.end() -1);
}
}
else
{
WriteConsoleA(oh, "*", 1, &count, NULL);
result.push_back(c);
}
}
// Restore the console mode
SetConsoleMode(ih, (ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
cout << endl << endl << setw(70) << setfill('-') << "-" << endl << endl;
return result;
}