Advertisement
Guest User

reeee

a guest
Oct 29th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. void Login();
  8. bool CheckCredentials(string, string);
  9.  
  10.  
  11. int main()
  12. {
  13.  
  14. string username;
  15. string password;
  16.  
  17.  
  18. Login();
  19. CheckCredentials(username, password);
  20.  
  21. return 0;
  22. }
  23. void Login()
  24. {
  25. ifstream infile;
  26. string username;
  27. string password;
  28. int tries = 0;
  29.  
  30. cout << "Enter in your username and password." << endl;
  31. cout << "Username: ";
  32. cin >> username;
  33. cout << "Password: ";
  34. cin >> password;
  35.  
  36. while (!CheckCredentials(username, password) && tries < 3)
  37. {
  38. tries++;
  39. cout << "Wrong password or username. you have " << 3 - tries << "tries left" << endl;
  40. cout << "Enter in your username and password." << endl;
  41. cout << "Username: ";
  42. cin >> username;
  43. cout << "Password: ";
  44. cin >> password;
  45.  
  46. }
  47.  
  48. if (tries > 2)
  49. {
  50. cout << "You have exceeded the maximum amount of attempts. Try again in 24 hours." << endl;
  51. }
  52. if (CheckCredentials(username, password))
  53. {
  54. cout << "Access Granted" << endl;
  55. }
  56. }
  57.  
  58. bool CheckCredentials(string username, string password)
  59. {
  60. string cUser, cPass;
  61. ifstream infile;
  62.  
  63. infile.open("correctData.txt");
  64.  
  65. getline(infile, cUser);
  66. getline(infile, cPass);
  67.  
  68. if (username == cUser && password == cPass)
  69. {
  70. return true;
  71. }
  72. else
  73. {
  74. return false;
  75. }
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement