8 #include "FileAuthController.h"
10 FileAuthController::FileAuthController(
string filename,
string delimiter) {
11 this->filename = filename;
12 this->delimiter = delimiter;
15 FileAuthController::~FileAuthController() {
19 string FileAuthController::treat_password(
string password)
24 bool FileAuthController::isInitialized()
26 ifstream ifs(this->filename.c_str());
27 bool fl = ifs.is_open();
32 bool FileAuthController::authenticate(
string username,
string password)
34 password = treat_password(password);
35 string userstamp = (username + delimiter + password);
36 ifstream ifs(this->filename.c_str());
40 while(getline(ifs, temp))
42 if(temp.find(userstamp)!=string::npos)
53 bool FileAuthController::authenticateSecurity(
string username,
string password)
55 password = treat_password(password);
56 ifstream ifs(this->filename.c_str());
60 while(getline(ifs, temp))
63 StringUtil::split(tempv, temp, (this->delimiter));
64 if(tempv.size()>=2 && tempv.at(0)==username && tempv.at(1)==password)
75 bool FileAuthController::getPassword(
string username,
string &passwd)
78 ifstream ifs(this->filename.c_str());
79 if(ifs.is_open() && username!=
"")
82 while(getline(ifs, temp))
85 StringUtil::split(tempv, temp, (this->delimiter));
86 if(tempv.size()>=2 && tempv.at(0)==username)
99 string FileAuthController::getUserRole(
string username)
102 ifstream ifs(this->filename.c_str());
103 if(ifs.is_open() && username!=
"")
106 while(getline(ifs, temp))
108 vector<string> tempv;
109 StringUtil::split(tempv, temp, (this->delimiter));
110 if(tempv.size()>=3 && tempv.at(0)==username)
123 string FileAuthController::get(
string username,
int pos)
126 ifstream ifs(this->filename.c_str());
127 if(ifs.is_open() && username!=
"")
130 while(getline(ifs, temp))
132 vector<string> tempv;
133 StringUtil::split(tempv, temp, (this->delimiter));
134 if((
int)tempv.size()>pos && tempv.at(0)==username)
138 return tempv.at(pos);