Advertisement
Guest User

LogIn

a guest
Mar 29th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool IsLoggedIn()
  8. {
  9.     string username, password, un, pw;
  10.  
  11.     cout << "Enter username: ";
  12.     cin >> username;
  13.     cout << "Enter Password: ";
  14.     cin >> password;
  15.  
  16.     ifstream read("D:\\C++\\Console\\Users\\Users.txt");
  17.     getline(read, un);
  18.     getline(read, pw);
  19.  
  20.     if (un == username && pw == password)
  21.     {
  22.         return true;
  23.     }
  24.     else
  25.     {
  26.         return false;
  27.     }
  28. }
  29.  
  30. int main()
  31. {
  32.     int choice;
  33.  
  34.     cout << "1: Register\n2: Login\nYour choice: "; cin >> choice;
  35.     if (choice == 1)
  36.     {
  37.         string username, password;
  38.  
  39.         cout << "select a username: "; cin >> username;
  40.         cout << "select a password: "; cin >> password;
  41.  
  42.         ofstream file;
  43.         file.open("D:\\C++\\Console\\Users\\Users.txt");
  44.  
  45.         file << username << "  :  " << password << "\r";
  46.  
  47.         file.close();
  48.  
  49.         main();
  50.     }
  51.     else if (choice == 2)
  52.     {
  53.         bool status = IsLoggedIn();
  54.         if (!status)
  55.         {
  56.             cout << "False Login!" << endl;
  57.             system("PAUSE");
  58.             return 0;
  59.         }
  60.         else
  61.         {
  62.             cout << "Succesfully loggin in!" << endl;
  63.             system("PAUSE");
  64.             return 1;
  65.         }
  66.     }
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement