You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.6 KiB

#include<fstream>
#include<string>
#include<string>
#include<graphics.h>
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;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE>
int find_username(std::string input) {
for (int i = 0; i < num; i++) {
if (input == username[i]) return i;
}
return -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>򷵻<EFBFBD>-1
}
// <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ӧ
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)"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (LPCTSTR)"<EFBFBD><EFBFBD>¼", (LPCTSTR)"0", 0, 0, 0);
// is_cancel = !CusInputBox(tempInput, 256, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>");
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)"<EFBFBD>޴<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (LPCTSTR)"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MB_OK); //<2F><>ʾ<EFBFBD><CABE>
}
if (correct) break;
}
while (true) {
bool correct = false;
is_cancel = !InputBox((LPTSTR) & (temp_password), 10, (LPCTSTR)"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (LPCTSTR)"<EFBFBD><EFBFBD>¼", (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)"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", (LPCTSTR)"<EFBFBD><EFBFBD>¼", MB_OK); //<2F><>ʾ<EFBFBD><CABE>
}
if (correct) {
break;
}
}
::MessageBox(GetHWnd(), (LPCTSTR)"<EFBFBD><EFBFBD>½<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>", (LPCTSTR)"Hello", MB_OK);
}