#include #include #include using namespace std; ifstream FIn_Login; ofstream FOut_Login; ifstream FIn_Password; ofstream FOut_Password; enum Check { Login = 1, Password = 2 }; class Person { public: void Login(); void Register(); bool Check(string word, int a); int unitForLogin = 0; int unitForPassWord = 0; private: string login; string firstPassword; string secondPassword; }; void Menu(); int main() { Menu(); FIn_Login.close(); FOut_Login.close(); FIn_Password.close(); FOut_Password.close(); } void Person::Login() { cout << "Insert Login :"; cin >> login; if (Check(login, Check::Login)) { cout << "Insert Password :"; cin >> firstPassword; if (Check(firstPassword, Check::Password)) { cout << "Correct."; } else { cout << "Incorrect."; } } else { cout << "Wrong login."; } } void Person::Register() { cout << "Insert Login :"; cin >> login; cout << "Insert Password :"; cin >> firstPassword; cout << "Insert Password again :"; cin >> secondPassword; if (Check(login, Check::Login)) { cout << "Login is Taken" << endl; Register(); } else if (!Check(login, Check::Login)) { if (firstPassword == secondPassword) { cout << endl << "Successful Register."; FOut_Login << login << endl; FOut_Password << firstPassword << endl; } else { cout << "Password is not the same."; } } } void Menu() { FIn_Login.open("Login.txt", ios::app); FIn_Password.open("Password.txt", ios::app); FOut_Login.open("Login.txt", ios::app); FOut_Password.open("Password.txt", ios::app); if (FOut_Login.is_open() && FOut_Password.is_open()) { cout << "File is Open" << endl; } else { cout << "File is Not Open" << endl; } Person ObjPerson; int i; cout << "Choice Options :" << endl; cout << "1. Login." << endl; cout << "2. Register." << endl; cin >> i; system("CLS"); if (i == 1) { ObjPerson.Login(); } else if (i == 2) { ObjPerson.Register(); } else { cout << "ERROR!" << endl; } } bool Person::Check(string word, int a) { string msg = ""; bool checking = false; if (Check::Login) { while (!FIn_Login.eof()) { string msg = ""; FIn_Login >> msg; if (msg == word) { checking = true; break; } else { checking = false; } } } else if (Check::Password) { while (!FIn_Password.eof()) { string msg = ""; FIn_Password >> msg; if (msg == word) { checking = true; break; } else { checking = false; } } } return checking; }