by Lucaci Andrei Fri Nov 09, 2012 10:33 pm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | /* * usrpass.cpp * usrpass.cpp is licensed under GNU GENERAL PUBLIC LICENSE * Created on: Nov 10, 2012 * Author: sin */ #include <iostream> #include <string> #include <vector> using namespace std;
class Pair{ string username, password; public: Pair(string usr, string pas){ username=usr; password=pas; }
string getUsr(){return username;} string getPas(){return password;}
bool const operator==(Pair& rhs){ return (this->username==rhs.getUsr() && this->password==rhs.getPas()); }
bool const operator<(Pair &rhs){ return (this->username<rhs.getUsr() && this->password<rhs.getPas()); }
bool const operator>(Pair &rhs){ return (this->username>rhs.getUsr() && this->password>rhs.getPas()); }
bool const operator!=(Pair &rhs){ return (this->username!=rhs.getUsr() && this->password!=rhs.getPas()); } };
bool check(vector<Pair> list, Pair elem){ vector<Pair>::iterator it=list.begin(); while (it!=list.end() && *it!=elem) ++it; return (it!=list.end()); }
int main(){ vector<Pair> db; db.push_back(Pair("admin", "1234")); db.push_back(Pair("omg", "5678")); string u, p; cout<<"username: "; cin>>u; cout<<"password: "; cin>>p; if (check(db, Pair(u, p))) cout<<"access granted.\n"; else cout<<"invalid username/password.\n"; return 0; }
|