密码尝试限制
Password attempt limit
本文关键字:密码 更新时间:2023-10-16
这里有一个c++新手。
如何限制在这个程序中输入密码的次数?到目前为止,它会重新打印,直到输入正确的密码。我想设置3次尝试的限制,并执行"尝试限制达到"或类似的东西。
{
string password;
while (true)
{
cout << "Please enter your password.n";
cin >> password;
if (password == "password")
{
cout << "Welcome!n";
break;
}
cout << "Please try again.n";
}
}
提前感谢,
杰斯。
您可以使用for
循环:
string password;
//Ask for a password as long as the user hasn't incorrectly entered one three or more times
for (int tries = 0; tries < 3; ++tries)
{
cout << "Please enter your password.n";
cin >> password;
if (password == "password")
{
cout << "Welcome!n";
break;
}
cout << "Please try again.n";
}
//If the password limit was reached without a correct password, send them an error message
if (password != "password") cout << "Sorry, try again later.n";
相关文章:
- c++中的oop(密码生成)
- 密码登录程序将永远循环并显示不正确的结果
- OpenSSL没有共享密码
- Cryptopp:获取密码输入的填充字符串
- 密码长度验证 (c++)
- C++ win32 如何使密码字段可选并启用复制和粘贴?
- 仿射密码解密,输出大小写不同
- 替换密码:哪一个?
- 无法使用 openssl 服务器,因为密码已过时...什么的...ERR_SSL_VERSION_OR_CIPHER_MISMATCH
- 如何使用 c++ 在 sqlite3 中打开受密码保护的数据库?
- 根据用户名和密码 Qt C++重新访问数据库值
- C++密码问题
- 无法在 Cocos2dx 中使用受密码保护的 zip 文件
- 如何使用librdkafka设置明文协议(无SASL)的用户名和密码?
- 如何将凯撒密码的元素从字符串更改为字符串
- 如何在C++的凯撒密码程序中包含空格?
- 运行密钥密码解密知道密钥?
- 如何在 c++ 中将密码和用户名保存到 .txt 文件中.如果用户尝试登录,我仍然希望能够检索它们
- 当PSO细粒度策略对使用AdsGetObject MSDN API的Windows操作系统生效时,如何获取用户密码到期日
- 密码显示双字母 c++ 的问题