Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. /// Returns bool for whether or not username & password combo are matched
  2. int logIn()
  3. {
  4. string un, pw, fn, ln, city, state;
  5. int choice = 0;
  6. int id;
  7. bool option = false;
  8.  
  9. while (!option)
  10. {
  11. while (choice != 1 && choice != 2 && choice != 3)
  12. {
  13. cout << "\t- WELCOME TO SPONGEBOOK -" << endl;
  14. cout << "1. Log in " << endl;
  15. cout << "2. Create an account " << endl;
  16. cout << "3. Quit " << endl;
  17. cout << "\nEnter choice: ";
  18. cin >> choice;
  19. cout << endl;
  20. }
  21.  
  22. if (choice == 1)
  23. {
  24. int count = 0;
  25.  
  26. while (true)
  27. {
  28. string userInput;
  29.  
  30. cout << "\t- LOG IN -" << endl
  31. << "Username: ";
  32. cin >> un;
  33. cout << "Password: ";
  34. cin >> pw;
  35.  
  36. for (int i = 1; i <= userID.size(); i++)
  37. {
  38. if (un == userID[i].getUsername() && pw == userID[i].getPassword())
  39. {
  40. cout << "\n\t*** Login successful ***\n" << endl;
  41. id = i;
  42. option = true;
  43. return id;
  44. }
  45. }
  46.  
  47. cout << "\n\t*** Incorrect username or password. Please try again **" << endl;
  48. count ++;
  49.  
  50. if (count > 3)
  51. {
  52. while (userInput != "YES" && userInput != "NO")
  53. {
  54. cout << "\nMultiple failed attempts. Would you like to go back to the main menu? ";
  55. cin >> userInput;
  56. transform(userInput.begin(), userInput.end(), userInput.begin(),::toupper);
  57. }
  58.  
  59. if (userInput == "YES")
  60. {
  61. cout << endl;
  62. choice = 0;
  63. option = true;
  64. return false;
  65. }
  66. else if (userInput == "NO")
  67. {
  68. choice = 1;
  69. count = 0;
  70. }
  71.  
  72. }
  73.  
  74. }
  75. }
  76. else if (choice == 2)
  77. {
  78. cout << "\t- CREATE AN ACCOUNT -" << endl
  79. << "First name: ";
  80. cin >> fn;
  81.  
  82. cout << "Last name: ";
  83. cin >> ln;
  84.  
  85. cout << "Username: ";
  86. cin >> un;
  87.  
  88. cout << "Password: ";
  89. cin >> pw;
  90.  
  91. cout << "City: ";
  92. cin.ignore();
  93. getline(cin, city);
  94.  
  95. cout << "State: ";
  96. cin >> ws;
  97. cin >> state;
  98.  
  99. id = userID.size() + 1;
  100.  
  101. User newUser(fn, ln, un, pw, city, state, id);
  102. userID.push_back(newUser);
  103.  
  104. cout << "\n\t*** Account successfully created. You may now log in ***\n" << endl;
  105. choice = 0;
  106. }
  107. else if (choice == 3)
  108. {
  109. cout << "\t- GOODBYE! -" << endl;
  110. exit(0);
  111. }
  112. }
  113. return id;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement