相关疑难解决方法(0)

从std :: cin读取密码

我需要从标准输入读取密码,并且不想std::cin回显用户输入的字符...

如何禁用std :: cin的回声?

这是我目前使用的代码:

string passwd;
cout << "Enter the password: ";
getline( cin, passwd );
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种与操作系统无关的方法来做到这一点. 这里有一些方法可以在Windows和*nix中执行此操作.

c++ stl password-protection

53
推荐指数
3
解决办法
2万
查看次数

C++密码屏蔽

我正在编写一个代码来接收密码输入.下面是我的代码...程序运行良好,但问题是除了数字和字母字符之外的其他键也被读取,例如删除,插入等等我能否知道如何避免它?TQ ...

string pw="";
char c=' ';

while(c != 13) //Loop until 'Enter' is pressed
{
    c = _getch();
    if(c==13)
        break;

    if(c==8)
    {
        if(pw.size()!=0)   //delete only if there is input 
        {
            cout<<"\b \b";
            pw.erase(pw.size()-1);
        }
    }

    if((c>47&&c<58)||(c>64&&c<91)||(c>96&&c<123))  //ASCii code for integer and alphabet
    {
        pw += c;
        cout << "*";
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ passwords input masking

3
推荐指数
1
解决办法
4012
查看次数

标签 统计

c++ ×2

input ×1

masking ×1

password-protection ×1

passwords ×1

stl ×1