Facebook
From sdf, 1 Year ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 88
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. ifstream FIn_Login;
  7. ofstream FOut_Login;
  8.  
  9. ifstream FIn_Password;
  10. ofstream FOut_Password;
  11.  
  12. enum Check
  13. {
  14.         Login = 1,
  15.         Password = 2
  16. };
  17.  
  18. class Person
  19. {
  20. public:
  21.         void Login();
  22.         void Register();
  23.         bool Check(string word, int a);
  24.  
  25.         int unitForLogin = 0;
  26.         int unitForPassWord = 0;
  27. private:
  28.         string login;
  29.         string firstPassword;
  30.         string secondPassword;
  31. };
  32.  
  33. void Menu();
  34.  
  35. int main()
  36. {
  37.         Menu();
  38.  
  39.         FIn_Login.close();
  40.         FOut_Login.close();
  41.         FIn_Password.close();
  42.         FOut_Password.close();
  43. }
  44.  
  45. void Person::Login()
  46. {
  47.         cout << "Insert Login :";
  48.         cin >> login;
  49.  
  50.         if (Check(login, Check::Login))
  51.         {
  52.                 cout << "Insert Password :";
  53.                 cin >> firstPassword;
  54.                 if (Check(firstPassword, Check::Password))
  55.                 {
  56.                                 cout << "Correct.";
  57.                 }
  58.                 else
  59.                 {
  60.                         cout << "Incorrect.";
  61.                 }
  62.         }
  63.         else
  64.         {
  65.                 cout << "Wrong login.";
  66.         }
  67. }
  68. void Person::Register()
  69. {
  70.         cout << "Insert Login :";
  71.         cin >> login;
  72.         cout << "Insert Password :";
  73.         cin >> firstPassword;
  74.         cout << "Insert Password again :";
  75.         cin >> secondPassword;
  76.  
  77.         if (Check(login, Check::Login))
  78.         {
  79.                 cout << "Login is Taken" << endl;
  80.                 Register();
  81.         }
  82.         else if (!Check(login, Check::Login))
  83.         {
  84.                 if (firstPassword == secondPassword)
  85.                 {
  86.                         cout << endl << "Successful Register.";
  87.                         FOut_Login <<  login << endl;
  88.                         FOut_Password << firstPassword << endl;
  89.                 }
  90.                 else
  91.                 {
  92.                         cout << "Password is not the same.";
  93.                 }
  94.         }
  95. }
  96. void Menu()
  97. {
  98.         FIn_Login.open("Login.txt", ios::app);
  99.         FIn_Password.open("Password.txt", ios::app);
  100.  
  101.         FOut_Login.open("Login.txt", ios::app);
  102.         FOut_Password.open("Password.txt", ios::app);
  103.  
  104.         if (FOut_Login.is_open() && FOut_Password.is_open())
  105.         {
  106.                 cout << "File is Open" << endl;
  107.         }
  108.         else
  109.         {
  110.                 cout << "File is Not Open" << endl;
  111.         }
  112.  
  113.         Person ObjPerson;
  114.         int i;
  115.         cout << "Choice Options :" << endl;
  116.         cout << "1. Login." << endl;
  117.         cout << "2. Register." << endl;
  118.         cin >> i;
  119.         system("CLS");
  120.         if (i == 1)
  121.         {
  122.                 ObjPerson.Login();
  123.         }
  124.         else if (i == 2)
  125.         {
  126.                 ObjPerson.Register();
  127.         }
  128.         else
  129.         {
  130.                 cout << "ERROR!" << endl;
  131.         }
  132. }
  133. bool Person::Check(string word, int a)
  134. {
  135.         string msg = "";
  136.         bool checking = false;
  137.         if (Check::Login)
  138.         {
  139.                 while (!FIn_Login.eof())
  140.                 {
  141.                         string msg = "";
  142.                         FIn_Login >> msg;
  143.                         if (msg == word)
  144.                         {
  145.                                 checking = true;
  146.                                 break;
  147.                         }
  148.                         else
  149.                         {
  150.                                 checking = false;
  151.                         }
  152.                 }
  153.         }
  154.         else if (Check::Password)
  155.         {
  156.                 while (!FIn_Password.eof())
  157.                 {
  158.                         string msg = "";
  159.                         FIn_Password >> msg;
  160.                         if (msg == word)
  161.                         {
  162.                                 checking = true;
  163.                                 break;
  164.                         }
  165.                         else
  166.                         {
  167.                                 checking = false;
  168.                         }
  169.                 }
  170.         }
  171.         return checking;
  172. }
  173.