Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class User {
- private:
- string name;
- string password;
- int rank;
- public:
- User(string name, string password, int Rank) {
- this->name = name;
- this->password = password;
- rank = Rank;
- }
- User() {
- name = "n/a";
- password = "";
- rank = -1;
- }
- string getName() {
- return name;
- }
- void setName(string newName) {
- name = newName;
- }
- void printName() {
- cout << name << endl;
- }
- void setPassword(string password) {
- this->password = password;
- }
- int getRank() {
- return rank;
- }
- void setRank(int rank) {
- this->rank = rank;
- }
- void printRank() {
- cout << rank << endl;
- }
- bool auth(string name, string password) {
- if(this->name == name && this->password == password) {
- return true;
- } else {
- return false;
- }
- }
- bool auth2(string name, string password) {
- return this->name == name && this->password == password;
- }
- void print1() {
- cout << "User[name=" << this->name << ", rank=" << this->rank << "]\n";
- }
- void print2() {
- string kecske = "******************************************************************************************************";
- cout << "User[name=" << this->name << ", password=" << kecske.substr(0, this->password.length()) << ", rank=" << this->rank << "]\n";
- }
- bool check() {
- return this->rank >= 1;
- }
- string checkStr() {
- if(check()) {
- return "igen";
- } else {
- return "nem";
- }
- }
- void print3(){
- cout << "User[name=" << this->name;
- cout << ", password=";
- for(int i=0;i<password.length();++i){
- cout << "*";
- }
- cout << ", rank=" << this->rank << endl;
- }
- };
- int main(){
- User admin = User("Admin", "nimda", 1);
- User user1 = User("User1", "pass1", 0);
- User user2 = User("User2", "pass2", 0);
- User user3 = User("User3", "pass3", 0);
- User unknown = User();
- admin.print1();
- cout << user1.check() << endl;
- cout << admin.checkStr() << endl;
- admin.print2();
- admin.setPassword("123456");
- admin.print3();
- cout << endl;
- User alma[4]={admin,user1,user2,user3};
- string tempuser,temppass;
- cout << "username:";
- cin >>tempuser;
- cout << endl;
- cout << "password:";
- cin >>temppass;
- for(int i=0;i<4;++4){
- if(alma[i].auth2(string tempuser,string temppass)){
- cout << alma[i].print3() << endl;
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement