0

**I want a way to hide the password when I type in console **

bool User::isLogIn(){
string username, password, file_line;
cout << "Enter username:";
cin >> username;
cout << "Enter password:";
cin >> password;
ifstream infile;
infile.open("users.txt");
if (!infile.is_open()){
    cout << "Error while opening the file...";
}
else{
    string str;
    while (getline(infile, str)){

        vector<string> newVector = split(str);
        string username_from_file = newVector[1];
        string password_from_file = newVector[3];
        if ((username_from_file.compare(username) == 0) && (password_from_file.compare(password)) == 0){
            return true;
        }
    }
}
return false;
}

Can anyone tell me how to make it so that when you enter in the password it shows as "*"'s?

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54
  • You will probably need some help from the operating system. One way would be to use an operating system API to intercept all key presses and then send `*`'s to the console. – wally Jan 01 '17 at 14:54

1 Answers1

1

You cannot do this with standard IO.

You need to use a library like ncurses

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • Or at least disable cooked mode on terminal, disable echo of user input and write * on key press. Nurses works probably make it easier. – erik258 Jan 01 '17 at 15:18