Advertisement
Guest User

Untitled

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