Hey i am trying to build a secure console app to store all the usernames and passwords at one place and access them through a master password.
I inserted a module of code for master password enterance and in that programm the password is not getting backspaced...
Someone pls help me. this is the code i have so far.
Its actually erasing stars but not deleting the character from string password. Help me!
string password = "";
char c = ' ';
while(c != 13) //Loop until 'Enter' is pressed
{
c = getch();
password += c;
cout << "*";
}
#include <iostream>
#include <string>
#include <conio.h>
usingnamespace std;
int main()
{
string password; // no need to init string with ""; that's done by constructor
char c = ' ';
while(c != 13) //Loop until 'Enter' is pressed
{
c = getch(); // from conio.h; with VC++, this must sometimes be _getch()
if(c == 8) // backspace
{
if(!password.empty()) // protect against over eager backspacing
{
cout << "\b \b";
password.resize(password.length() - 1);
}
}
elseif(isprint(c)) // ignore control chars (isalnum might be better?)
{
password += c;
cout << "*";
}
}
cout << endl;
cout << "got: " << password << endl;
cout << endl;
return 0;
}
Notes
'\b' is the backspace char, but it doesn't erase. So you go back, write a space, then go back again (btw - if you search this forum for \b, you'll find people discussing this same problem!)