Advertisement
Guest User

Beat's login code

a guest
Jul 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6. string userName;
  7. string userPassword;
  8. int loginAttempt = 0;
  9.  
  10. while (loginAttempt < 5)
  11. {
  12. cout << "Please enter your user name: ";
  13. cin >> userName;
  14. cout << "Please enter your user password: ";
  15. cin >> userPassword;
  16.  
  17. if (userName == "greg" && userPassword == "dunn")
  18. {
  19. cout << "Welcome Greg!\n";
  20. break;
  21. }
  22. else if (userName == "patrick" && userPassword == "dunn")
  23. {
  24. cout << "Welcome Patrick!\n";
  25. break;
  26. }
  27. else
  28. {
  29. cout << "Invalid login attempt. Please try again.\n" << '\n';
  30. loginAttempt++;
  31. }
  32. }
  33. if (loginAttempt == 5)
  34. {
  35. cout << "Too many login attempts! The program will now terminate.";
  36. return 0;
  37. }
  38.  
  39. cout << "Thank you for logging in.\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement