Advertisement
Guest User

????

a guest
Mar 12th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string.h>
  4. using namespace std;
  5.  
  6. string username;
  7. string password;
  8.  
  9.  
  10. struct user
  11. {
  12. string username;
  13. string password;
  14. };
  15.  
  16. void registerUser(user);
  17. void login(user);
  18.  
  19. int main()
  20. {
  21. user USER;
  22. int choice;
  23.  
  24. cout << "Enter 1 to register or 2 to login: " << endl;
  25. cout << "Your choice: ";
  26. cin >> choice;
  27.  
  28. if(choice == 1)
  29. registerUser(USER);
  30. else if(choice == 2)
  31. login(USER);
  32. }
  33.  
  34. void registerUser(user USER)
  35. {
  36. ofstream outFile;
  37.  
  38. outFile.open("Users Data.txt");
  39.  
  40. cout << "Enter username: ";
  41. cin >> USER.username;
  42. cout << "Enter password: ";
  43. cin >> USER.password;
  44.  
  45. outFile << "Username: " << USER.username << endl;
  46. outFile << "Password: " << USER.password << endl;
  47.  
  48. outFile.close();
  49. }
  50.  
  51. void login(user USER)
  52. {
  53. ifstream inFile;
  54. inFile.open("Users Data.txt");
  55.  
  56. cout << "Enter your username: " ;
  57. cin>>username;
  58. cout << "Enter your password: " ;
  59. cin>>password;
  60.  
  61. inFile>>USER.username>>USER.password;
  62.  
  63. {
  64. if(username==USER.username)
  65. {
  66. if(password == USER.password)
  67. {
  68. cout << "Login successful!" << endl;
  69. }
  70. }
  71. else
  72. {
  73.  
  74. cout << "Login error! Please try again. " << endl;
  75.  
  76. }
  77. }
  78.  
  79.  
  80. inFile.close();
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement