Guest User

Untitled

a guest
Nov 29th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /*
  2. Program: Challenge 5
  3. Author: Chapman Siu
  4. Date: 5 Aug
  5.  
  6. Description:
  7. Your challenge for today is to create a program which is password protected, and wont open unless the correct user and password is given.
  8. For extra credit, have the user and password in a seperate .txt file.
  9. for even more extra credit, break into your own program :)
  10. */
  11.  
  12. #include <iostream>
  13. #include <string>
  14. #include <fstream>
  15.  
  16. using namespace std;
  17.  
  18. bool checkLogin(string User, string Pass);
  19.  
  20. bool checkLogin(string User, string Pass) {
  21. ifstream loginDet;
  22. loginDet.open("login.txt");
  23. string loginUser, loginPass;
  24.  
  25. if (loginDet.is_open()) {
  26. while(!loginDet.eof()) {
  27. getline(loginDet,loginUser);
  28. getline(loginDet,loginPass);
  29. }
  30. }
  31. loginDet.close();
  32.  
  33. if (User == loginUser && Pass == loginPass) {
  34. return true;
  35. }
  36. cout <<endl << "Incorrect Details. Try Again" << endl;
  37. return false;
  38. }
  39.  
  40. int main()
  41. {
  42. string user,pass;
  43.  
  44. cout << "Enter Username: " <<endl;
  45. cin >> user;
  46. cout << "Enter Password: " << endl;
  47. cin >> pass;
  48.  
  49. while(!checkLogin(user,pass)){
  50. cout << "Enter Username: " <<endl;
  51. cin >> user;
  52. cout << "Enter Password: " << endl;
  53. cin >> pass;
  54. }
  55.  
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment