Guest User

Untitled

a guest
Sep 18th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. string username;
  6. string password;
  7. int choice;
  8. string eUsername;
  9. string ePassword;
  10. bool approved=false;
  11.  
  12. void startUp () {
  13. cout << "To begin create an account, or log in!" << endl;
  14. cout << " To log in Enter '1' \n To create an account enter '2'" << endl;
  15. cin >> choice;
  16. }
  17.  
  18. void loggingIn () {
  19. cout << "Enter your username" << endl;
  20. cin >> eUsername;
  21. cout << "Enter your password" << endl;
  22. cin >> ePassword;
  23. ifstream inProfileData ("logIn.txt");
  24. inProfileData >> username >> password;
  25. if (password==ePassword&&username==eUsername) {
  26. approved=true;
  27. }
  28. else {
  29. approved = false;
  30. }
  31. }
  32.  
  33. void createAccount () {
  34. cout << "Create your username!" << endl;
  35. cin >> username;
  36. cout << "Good, now create a password" << endl;
  37. cin >> password;
  38. cout << "Good, now log in" << endl;
  39. ofstream profileData ("logIn.txt");
  40. profileData << username << " " << password << endl;
  41. }
  42.  
  43. void logInBody () {
  44. startUp ();
  45.  
  46. if (choice!=2&&choice!=1) {
  47. cout << "You must enter 1 or 2!" << endl << endl;
  48. startUp();
  49. }
  50. if (choice ==2) {
  51. createAccount ();
  52. loggingIn ();
  53. }
  54.  
  55. if (choice == 1) {
  56. loggingIn();
  57. }
  58. if (approved==true) {
  59. cout << "Congratiolations, you are now logged in! Enjoy!" << endl;
  60. }
  61. else {
  62. cout << " Username or password was incorrect, or you entered wrong data type." << endl << endl;
  63. }
  64. }
  65.  
  66. int main ()
  67. {
  68. int x=0;
  69. do {
  70. logInBody ();
  71. x++;
  72. }
  73. while (approved==false&&x<11);
  74. if (x==11) {
  75. cout << "Either you entered the wrong data type or you have reached the maximum amount of attempts allowed" << endl;
  76. }
  77. return 0;
  78. }
Add Comment
Please, Sign In to add comment