程序的密码
Password to a program
我做了一个应用程序,可以用矩阵解决一些计算问题,我想对用户进行身份验证,以便在程序启动时授予他们访问权限。
我会告诉你我已经做了什么。
int main()
{
const string USERNAME = "claudiu";
const string PASSWORD = "123456";
string usr, pass;
cout << "Enter Username : ";
cin >> usr;
if(usr.length() < 4)
{
cout << "Username length must be atleast 4 characters long.";
}
else
{
cout << "Enter Password : ";
cin >> pass;
if(pass.length() < 6)
{
cout << "Password length must be atleast 6 characters long";
}
else
{
if(usr == USERNAME && pass == PASSWORD)
{
cout << "nnSuccessfully granted access" << endl;
}
else
{
cout << "Invalid login details" << endl;
}
}
}
这就是我的代码的样子。我想做的是,当我输入错误的用户名或错误的密码时,程序会显示我写的消息,然后让我引入另一个用户名和密码,当我正确引入它们时,程序启动。
我会创建一个logged_in
变量,然后在条件传递时将其设置为 true
并在 while 循环中运行整个登录过程:
#include <iostream>
#include <string>
using namespace std;
int main()
{
const string USERNAME = "claudiu";
const string PASSWORD = "123456";
string usr, pass;
bool logged_in = false;
while (!logged_in)
{
cout << "Enter Username : ";
cin >> usr;
if (usr.length() < 4)
{
cout << "Username length must be atleast 4 characters long.";
}
else
{
cout << "Enter Password : ";
cin >> pass;
if (pass.length() < 6)
{
cout << "Password length must be atleast 6 characters long";
}
else
{
if (usr == USERNAME && pass == PASSWORD)
{
cout << "nnSuccessfully granted access" << endl;
logged_in = true;
}
else
{
cout << "Invalid login details" << endl;
}
}
}
}
cout << "Passed login!n";
}
相关文章:
- 密码登录程序将永远循环并显示不正确的结果
- 如何在C++的凯撒密码程序中包含空格?
- 即使密码/用户无效,程序仍会继续
- 程序输入密码并解锁窗口7,8,10
- 凯撒密码程序中"Debug Assertion Failed!"问题
- Atbash 密码程序 A = Z, B = Y, C = X
- 密码验证程序
- C++应用程序连接到网站服务器并根据密码检索文件
- 如何制作一个从文件中读取密码并与用户编写的密码进行比较的 c++ 程序
- 简单的密码哈希程序 c++
- 在我的C++凯撒密码程序中出现错误
- 凯撒密码程序
- C++ 密码程序上的计数循环
- 密码程序在 C++ 中不起作用
- C++密码程序,字符串在后排时不会删除最后一个字符
- 密码程序来掩盖字符 - 怎么了?
- 密码程序
- c++凯撒密码程序执行错误字符
- 我的密码程序不更改密码
- c++密码程序