AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Join the forum, it's quick and easy

AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.
AndreiL
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Simple username and password verification

Go down

Simple username and password verification Empty Simple username and password verification

Post 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;
}

Lucaci Andrei
Lucaci Andrei
"Tata Lor"
Simple username and password verification 138

Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 31
Location : Cluj-Napoca

http://www.andreil.wgz.ro

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum