Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class User {
  5. private:
  6. string name;
  7. string password;
  8. int rank;
  9. public:
  10. User(string name, string password, int Rank) {
  11. this->name = name;
  12. this->password = password;
  13. rank = Rank;
  14. }
  15. User() {
  16. name = "n/a";
  17. password = "";
  18. rank = -1;
  19. }
  20. string getName() {
  21. return name;
  22. }
  23. void setName(string newName) {
  24. name = newName;
  25. }
  26. void printName() {
  27. cout << name << endl;
  28. }
  29. void setPassword(string password) {
  30. this->password = password;
  31. }
  32. int getRank() {
  33. return rank;
  34. }
  35. void setRank(int rank) {
  36. this->rank = rank;
  37. }
  38. void printRank() {
  39. cout << rank << endl;
  40. }
  41. bool auth(string name, string password) {
  42. if(this->name == name && this->password == password) {
  43. return true;
  44. } else {
  45. return false;
  46. }
  47. }
  48. bool auth2(string name, string password) {
  49. return this->name == name && this->password == password;
  50. }
  51. void print1() {
  52. cout << "User[name=" << this->name << ", rank=" << this->rank << "]\n";
  53. }
  54. void print2() {
  55. string kecske = "******************************************************************************************************";
  56. cout << "User[name=" << this->name << ", password=" << kecske.substr(0, this->password.length()) << ", rank=" << this->rank << "]\n";
  57. }
  58. bool check() {
  59. return this->rank >= 1;
  60. }
  61. string checkStr() {
  62. if(check()) {
  63. return "igen";
  64. } else {
  65. return "nem";
  66. }
  67. }
  68. void print3(){
  69. cout << "User[name=" << this->name;
  70. cout << ", password=";
  71. for(int i=0;i<password.length();++i){
  72. cout << "*";
  73. }
  74. cout << ", rank=" << this->rank << endl;
  75. }
  76. };
  77. int main(){
  78. User admin = User("Admin", "nimda", 1);
  79. User user1 = User("User1", "pass1", 0);
  80. User user2 = User("User2", "pass2", 0);
  81. User user3 = User("User3", "pass3", 0);
  82. User unknown = User();
  83. admin.print1();
  84. cout << user1.check() << endl;
  85. cout << admin.checkStr() << endl;
  86. admin.print2();
  87. admin.setPassword("123456");
  88. admin.print3();
  89. cout << endl;
  90. User alma[4]={admin,user1,user2,user3};
  91. string tempuser,temppass;
  92. cout << "username:";
  93. cin >>tempuser;
  94. cout << endl;
  95. cout << "password:";
  96. cin >>temppass;
  97. for(int i=0;i<4;++4){
  98. if(alma[i].auth2(string tempuser,string temppass)){
  99. cout << alma[i].print3() << endl;
  100. return 0;
  101. }
  102. }
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement