Advertisement
Guest User

Untitled

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