Advertisement
Guest User

Untitled

a guest
Sep 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. #define ACCOUNT_MAX 3
  6.  
  7. using namespace std;
  8.  
  9. class User
  10. {
  11. private:
  12. struct Accounts {string user, password, firstName;};
  13. struct Accounts accs[ACCOUNT_MAX];
  14. bool online;
  15.  
  16. void setAccounts()
  17. {
  18. accs[0].user = "admin";
  19. accs[0].password = "adminpw";
  20. accs[0].firstName = "Administrator";
  21. accs[1].user = "user01";
  22. accs[1].password = "user01pw";
  23. accs[1].firstName = "User 01";
  24. accs[2].user = "user02";
  25. accs[2].password = "user02pw";
  26. accs[2].firstName = "User 02";
  27. }
  28.  
  29. public:
  30. int Access(string user, string password)
  31. {
  32. int count = 0;
  33.  
  34. for (; count <= ACCOUNT_MAX; count++)
  35. {
  36. if (user.compare(this->accs[count].user) == 0 && password.compare(this->accs[count].password) == 0)
  37. {
  38. this->online = true;
  39. break;
  40. }
  41.  
  42. else
  43. this->online = false;
  44. }
  45.  
  46. return this->online;
  47. }
  48.  
  49. User() {}
  50. ~User() {}
  51. };
  52.  
  53. int main()
  54. {
  55. class User *managment = new User();
  56. string localUser, localPassword;
  57.  
  58. cout << "A system [Version 2.0]n" << endl;
  59.  
  60. do {
  61. cout << "User: ";
  62. cin >> localUser;
  63. cout << "Password: ";
  64. cin >> localPassword;
  65. } while (managment->Access(localUser, localPassword) == false);
  66.  
  67.  
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement