Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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. cout << "Enter username: "; cin >> username;
  11. cout << "Enter password: "; cin >> password;
  12.  
  13. ifstream read("data\\" + username + ".txt");
  14. getline(read, un);
  15. getline(read, pw);
  16.  
  17. if (un == username && pw == password)
  18. {
  19. return true;
  20. }
  21. else
  22. {
  23. return false;
  24. }
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. int choice;
  31.  
  32.  
  33. cout << "1: Register\n2: Login\nYour choice: "; cin >> choice;
  34. if (choice == 1)
  35. {
  36. string username, password;
  37.  
  38. cout << "select a username"; cin >> username;
  39. cout << "select a password"; cin >> password;
  40.  
  41. ofstream file;
  42. file.open("data\\" + username + ".txt");
  43. file << username << endl << password;
  44. file.close();
  45.  
  46. main();
  47. }
  48. else if (choice == 2)
  49. {
  50. bool status = IsLoggedIn();
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement