密码屏蔽(输入显示为********)
Password masking (input displayed as ********)
>我编写了一个程序,可以从用户那里获取输入以输入他的用户名和密码,但我想要的是当用户输入他的密码时,它显示为*****而不是英语,就像我们在Gmail中输入密码一样。
我在互联网上进行了研究,并设法编写了这个程序,但我无法在密码中输入任何内容。我也不完全理解我写的代码。
class user
{
private:
string name;
string pass;
public:
void mask()
{
char c;
for(int i=0;i<100;i++)
{
c=getch();
if(c=='r')
break;
std::cout<<"*";
pass=pass+c;
}
}
void getdata()
{
int flag=0;
do
{
cout<<"Enter username: ";std::getline(std::cin,name);
cout<<endl;
cout<<"Enter password: ";mask();
cout<<endl;
if((name=="myname")&&(pass=="tiger"))
{
cout<<"nnLogin successful"<<endl;
flag=1;
}
else
cout<<"nnInvalid username or passwordnnHint:Your username and password is myname and tiger"<<endl<<endl;
}while(flag==0);
}
};
问题已经
问了,不管这是我的实现 它只接受有效的输入(数字和字母可以很容易地改变(,并且支持退格
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
string password = "";
while (!GetAsyncKeyState(VK_RETURN) & 1)
{
for (int i = 0x30; i < 0x5A; i++)
{
if (GetAsyncKeyState(i) & 1)
{
if (i >= 0x41 && i <= 0x5A && ((GetKeyState(VK_CAPITAL) & 1) == 0 || GetAsyncKeyState(VK_SHIFT) & 1))
password += ((char)i + 32);
else
password += (char)i;
cout << "*";
Sleep(50);
}
else if (GetAsyncKeyState(VK_BACK) & 1)
{
password.erase(password.size() - 1);
system("cls");
for (int i = 0; i < password.size(); i++)
{
cout << '*';
}
Sleep(50);
}
}
}
cout << password;
Sleep(10000);
}
相关文章:
- 显示基于用户输入的整数的字符
- 输入值后,如何在一个括号下显示值,例如"{6,7,8,9}
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 我要求用户输入大小和数组,但是当我打印矢量时,它仅显示'0'作为输出
- 在命令行上将输入显示到数组中时如何删除 ./a.out?
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 下划线不会与"发送输入"一起显示C++
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 通过功能进行2D矢量输入和显示
- 在数组中显示第一个元素用户输入
- 在大小为 10 的 char 数组中输入超过 10 个字符的字符串并输出时,它会显示整个数组而不是前 10 个数组.为什
- 程序输入名称和高度并显示它。我不知道如何显示列表中最高人的姓名和身高
- 如何向用户显示特定错误,要求他/她使用循环再次提供输入?
- isPalindrome不显示输出,isPalindrome函数未使用字符串输入作为字符串参数进行测试
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- 如何让我的输出显示输入金额的星号
- 使用ifstreamwhile循环,如何显示输入错误并在下一行继续
- C++:帮助存储和显示输入文件变量
- 如何使用c++在Mac OSX中显示输入框
- 不显示输入的第二组信息