-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authentication.cpp
37 lines (31 loc) · 809 Bytes
/
Authentication.cpp
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
#include "Authentication.h"
#include "base64.h"
Authentication::Authentication(const std::string& name, const std::string& password)
{
this->name = name;
this->password = password;
this->valid = true;
}
Authentication::Authentication(const std::string& line)
{
this->valid = false;
size_t pos = line.find("Basic ");
if(pos == 0)
{
std::string decoded = base64_decode(line.substr(pos + 6, std::string::npos));
pos = decoded.find(':');
if(pos != std::string::npos)
{
this->name = decoded.substr(0, pos);
this->password = decoded.substr(pos + 1, std::string::npos);
this->valid = true;
}
}
}
bool Authentication::operator==(const Authentication& other) const
{
if(!this->valid)
return false;
return this->name == other.name &&
this->password == other.password;
}