【问题标题】:Using * to appear as password character in c++ [duplicate]使用 * 在 C++ 中显示为密码字符 [重复]
【发布时间】:2017-01-01 14:53:13
【问题描述】:

**我想在控制台输入时隐藏密码**

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;
}

谁能告诉我怎么做才能在输入密码时显示为“*”?

【问题讨论】:

  • 您可能需要操作系统的帮助。一种方法是使用操作系统 API 拦截所有按键,然后将 * 发送到控制台。

标签: c++


【解决方案1】:

标准 IO 无法做到这一点。

你需要使用像ncurses这样的库

【讨论】:

  • 或者至少禁用终端上的熟食模式,禁用用户输入的回显并在按键上写 *。护士的工作可能会让事情变得更容易。
猜你喜欢
  • 1970-01-01
  • 2022-01-25
  • 2013-03-25
  • 1970-01-01
  • 2016-08-09
  • 1970-01-01
  • 2019-12-21
  • 2013-10-31
  • 2016-06-20
相关资源
最近更新 更多