如何在 c++ 中将密码和用户名保存到 .txt 文件中.如果用户尝试登录,我仍然希望能够检索它们
How do I save passwords and usernames to a .txt file in c++. I still want to be able to retrieve them if the user tries to login
我正在启动一个基于控制台的在线银行(为了好玩(。我想知道如何保存注册帐户的人的用户名和密码(也许是.txt文件?我也想知道当他们尝试登录时,我将如何检查.txt文件中的用户名和密码。任何帮助,不胜感激。这是源代码
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <string>
#include <stdlib.h>
using namespace std;
bool gameOver;
// global variables
string EntryChoice;
int numberOfIncorrect = 5;
string NewUsername;
string NewPassword;
string LoginUsername;
string LoginPassword;
string NewFirstName;
string LoginFirstName;
string NewLastName;
string LoginLastName;
int Newage;
string Newgender;
int Loginage;
string LoginGender;
//declaration of functions
void Login();
void SignUp();
void BankCheck();
void BankError();
void Bank()
{
cout << "Welcome to the Bank of National Arabsn";
cout << "-------------------------------------n";
cout << "|To Sign Up type (Register) then Press Enter|n";
cout << "|To Login type (Login) then Press Enter|n";
cin >> EntryChoice;
BankCheck();
}
void BankCheck()
{
if (EntryChoice == "Login" || EntryChoice == "LOGIN" || EntryChoice == "login")
{
Login();
}
else if (EntryChoice == "REGISTER" || EntryChoice == "register" || EntryChoice == "Register")
{
SignUp();
}
else
{
system("cls");
BankError();
}
}
void BankError()
{
if (numberOfIncorrect == 1)
{
exit(1);
}
numberOfIncorrect -= 1;
cout << "Welcome to the Bank of National Arabsn";
cout << "-------------------------------------n";
cout << "|To Sign Up type (Register) then Press Enter|n";
cout << "|To Login type (Login) then Press Enter|n";
cout << "|ERROR| " << numberOfIncorrect << " Tries Left >> ";
cin >> EntryChoice;
BankCheck();
}
void Login()
{
system("cls");
cout << "Bank of United Arabs Login Pagen";
cout << "-------------------------------n";
cout << "Username: ";
cin >> LoginUsername;
cout << "nPassword:";
cin >> LoginPassword;
}
void SignUp()
{
system("cls");
cout << "Welcome to the Register Pagen";
cout << "----------------------------n";
cout << "Age: ";
cin >> Newage;
cout << "nGender: ";
cin >> Newgender;
cout << "nFirst name";
cin >> NewFirstName;
cout << "nLast Name";
cin >> NewLastName;
cout << "nUsername: ";
cin >> NewUsername;
cout << "nPassword";
cin >> NewPassword;
}
int main()
{
Bank();
return 0;
}
是的,你可以这样做。也许,每次您在注册时输入用户的数据时,都可以使用 c++ 文件运算符(阅读此内容:https://www.bogotobogo.com/cplusplus/fstream_input_output.php(同时将其存储到 txt 文件中,后跟一个分隔符来标记每条记录的末尾。 将文本文件中的格式保留为:
UserID1
Username1
Password1@
UserID2
Username2
Password2@
这里 @ 是一个分隔符。 要检索记录,请使用上述分隔符读取记录,在.txt文件中搜索用户名或 ID。如果找到记录,则按行分隔记录值并将其存储在变量中,然后与输入数据值进行比较。继续搜索,直到 EOF 标志为假。
相关文章:
- 如何在 c++ 中将密码和用户名保存到 .txt 文件中.如果用户尝试登录,我仍然希望能够检索它们
- Win7 C++ - 从以用户身份登录的服务启动可执行文件的问题
- 用户注销/登录后,创建托盘图标时出现罕见错误
- 是否有任何 C 函数或 API 来获取当前登录用户下运行的进程列表
- 如何从 Windows 上的服务在未登录用户的桌面上启动应用程序
- 获取 Windows 系统已加入 Azure AD 时登录用户的 UserPrincipalName
- 加密用户数据,而不会丢失安卓应用程序中的登录用户
- 如何检查用户登录到Windows的时间
- 嗨,我正在尝试编码一个允许用户在Visual C 中登录的按钮,程序正在运行,但表单对话框未显示
- 如何从非管理员用户获取当前登录的用户名、域名和用户 sid
- 我如何将登录的用户登录到当前会话中的域用户
- C++检查是否有用户登录到Windows7
- 如何添加基于时间的限制以阻止Windows用户登录
- 在C++中跟踪用户登录的可行性
- 应用程序是不可见的,如果没有任何用户登录从任务调度程序启动
- c++服务-模拟用户登录
- 在Linux/Mac上使用c++检测/等待用户登录
- C++:如何在 Windows 凭据管理器中以编程方式创建本地用户登录凭据,以便"runas /savecred"可以使用它?
- 如何在用户登录/关闭或PC进入睡眠/休眠时正确通知c++ Windows服务
- 如何在多个用户登录Windows时获取活动用户