Hey guys. I'm making a program which let user to login their details and passwords before enabling them to use it.
Caesar Cipher
Their login details are stored in the textfile called "login.txt".
the text contain..
1:admin:jmvrw12345:1
2:user1:dbna12345:1
3:user2:dbna12345:1
4:manager:vjwjpna12345:1 |
I've done the rest of the stuff but the issue is I'm unable to authenticate the user.
Let's say if he enters correctly it will be a success, he will be able to login.
I've cut the username and password using the delimiter ":"
I'm not very well verse in sstream so kinda confused what to do next.
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
|
bool::PCMF::authenticate(string id, string pw){
vector<string> file;
string line;
string temp;
ifstream dataFile("login.text");
User u;
if(dataFile.is_open()){
while(dataFile.good()){
getline(dataFile,line);
vector<string> s = PCMF::separator(line, delimiter);
u.id = atoi(s[0].c_str());
u.userName = s[1];
u.passwordCrypted = s[2];
u.isEnabled = atoi(s[3].c_str());
file.push_back(temp);
}//end loop
dataFile.close();
}//end if
//Problem for this part
for(vector<string>::const_iterator i = file.begin(); i != file.end(); i++){
}//end loop
}//authenticate
| |
The above shows that the function starts to read the textfile.
Then start to "cut" into different pieces so that the next time I want to authenticate, eg "id == id", it will be easy.
Anyone can help me with the codes for authenticate?
Oh this is wad I found from some other web, trying to do something similar to this but fail..
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
|
bool PosConsole::authenticate(string * userID, string * password)
{
for(vector<User>::iterator iteratorU=_userData.begin(); iteratorU!=_userData.end(); iteratorU++) {
if (iteratorU->userName == *userID)
{
if (iteratorU->isPasswordMatched(password))
{
if (iteratorU->isEnabled == false)
{
cout << "Your account is locked. Please contact our administrator." << endl;
return false;
}
iteratorU->numOfWrongAttempts = 0;
_currentUser = iteratorU.base();
return true;
} else {
iteratorU->numOfWrongAttempts ++;
if (iteratorU->numOfWrongAttempts >= 3)
iteratorU->isEnabled = false;
return false;
}
}
}
return false;
}
| |
Separator reference: to separate the lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
vector<string> PCMF::separator(string line, string delimiter){
vector<string> vectString;
while(!line.empty()){
int index = line.find_first_of(delimiter);
if (index != -1)
{
vectString.push_back(line.substr(0,index));
line = line.substr(index + 1,string::npos);
}//end if
else{
vectString.push_back(line.substr(0, string::npos));
line ="";
}//end else
}//end loop
| |