Advertisement
Guest User

Untitled

a guest
Oct 28th, 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 = 0;
  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. tries++;
  40. cout << "Wrong password or username. you have " << 3 - tries << "tries left" << endl;
  41. cout << "Enter in your username and password." << endl;
  42. cout << "Username: ";
  43. cin >> username;
  44. cout << "Password: ";
  45. cin >> password;
  46.  
  47. }
  48.  
  49. if (tries > 2)
  50. {
  51. cout << "You have exceeded the maximum amount of attempts. Try again in 24 hours." << endl;
  52. }
  53. if (CheckCredentials(username, password))
  54. {
  55. cout << "Access Granted" << endl;
  56. }
  57. }
  58.  
  59. bool CheckCredentials(string username, string password)
  60. {
  61. string cUser, cPass;
  62. ifstream infile;
  63.  
  64.  
  65. getline(infile, cUser);
  66.  
  67.  
  68. getline(infile, cPass);
  69.  
  70. if (username == cUser && password == cPass)
  71. {
  72.  
  73. }
  74. else
  75. {
  76. return false;
  77. }
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement