From eea2e6c1846767943d64c3152dd4fd71906d6ca7 Mon Sep 17 00:00:00 2001 From: mi84kabv9 Date: Sat, 8 Jun 2024 17:41:43 +0800 Subject: [PATCH] ADD file via upload --- Account.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Account.h diff --git a/Account.h b/Account.h new file mode 100644 index 0000000..64abbec --- /dev/null +++ b/Account.h @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +bool CusInputBox(char* input, int length, const char* prompt) { + std::cout << prompt << std::endl; + std::cin.getline(input, length); + return true; +} +class Account { +private: + int num; + std::string* username; + std::string* password; +public: + Account() { + username = NULL; + password = NULL; + num = 0; + } + int& get_num() { + return num; + } + std::string*& get_username() { + return username; + } + std::string*& get_password() { + return password; + } + // 查找输入是否在用户名队列之中 + int find_username(std::string input) { + for (int i = 0; i < num; i++) { + if (input == username[i]) return i; + } + return -1; // 若不在用户名队列之中则返回-1 + } + // 用户名与密码是否对应 + bool is_correct(int i, std::string input) { + return input == password[i]; + } +}; + +void init_Account(Account& account) { + std::fstream filename; + filename.open("account.txt"); + filename >> account.get_num(); + int n = account.get_num(); + account.get_username() = new std::string[n]; + account.get_password() = new std::string[n]; + for (int i = 0; i < n; i++) { + filename >> account.get_username()[i]; + filename >> account.get_password()[i]; + } + +} + + + + + +void log_in_2(Account& account) { + init_Account(account); + bool is_cancel = false; + std::string username; + std::string password; + int i = 0; + char temp_username[256]; + char temp_password[256]; + + while (true) { + bool correct = false; + is_cancel = !InputBox((LPTSTR) & (temp_username), 10, (LPCTSTR)"请输入用户名:", (LPCTSTR)"登录", (LPCTSTR)"0", 0, 0, 0); + // is_cancel = !CusInputBox(tempInput, 256, "请输入用户名:"); + if (is_cancel) exit(0); + else { + username = temp_username; + for (i = 0; i < account.get_num(); i++) { + std::string tempstr = account.get_username()[i]; + // username = (std::string)username; + if (tempstr == username) { + correct = true; + break; + } + } + if (!correct) ::MessageBox(GetHWnd(), (LPCTSTR)"无此用户,请重输", (LPCTSTR)"打开", MB_OK); //提示框 + } + if (correct) break; + } + while (true) { + bool correct = false; + is_cancel = !InputBox((LPTSTR) & (temp_password), 10, (LPCTSTR)"请输入密码:", (LPCTSTR)"登录", (LPCTSTR)"0", 0, 0, 0); + if (is_cancel) exit(0); + else { + password = temp_password; + if (account.get_password()[i] == password) correct = true; + if (!correct) ::MessageBox(GetHWnd(), (LPCTSTR)"密码错误,请重输", (LPCTSTR)"登录", MB_OK); //提示框 + } + if (correct) { + break; + } + } + ::MessageBox(GetHWnd(), (LPCTSTR)"登陆成功!", (LPCTSTR)"Hello", MB_OK); +} \ No newline at end of file