I'm writing a program which is supposed to have a login, with a password which is not echoed as it is typed in (that is, someone looking over the typer's shoulder can't read the screen to see what the password is). Someone suggested that I should use curses.h but is there any way I can do it without it?
#include <iostream>
#include <curses.h>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
string name;
string pass;
initscr();
cout << "login: ";
cin >> name;
cout << endl;
cout << "password: ";
noecho();
cin >> pass;
cout << endl;
echo();
cout << "Login incorrect." << endl;
cout << name << endl << pass << "." << endl;
}
*The code above doesn't really work because nothing the user types is echoed. So, (a) am I using the curses functions wrong, and/or (b) is there a better way to do this?