#include <string>
#include <iostream>
#include <unistd.h>
using namespace std;
int main(int argc, char **argv) {
string key = "Blah";
string key2 = "Blah";
string salt = "Bl";
string foo = crypt(key.c_str(), salt.c_str());
string foo2 = crypt(key2.c_str(), salt.c_str());
cout << foo << " ? " << foo2 << endl;
}
g++ -lcrypt -o blah blah.cpp
./blah
BlHgmTx6HdmHk ? BlHgmTx6HdmHk
if(brain == NULL || brain->GetType() != BRAIN_HUMAN)
return;
IBrainHuman * hBrain = (dynamic_cast<IBrainHuman*>(brain));
thePassword = hBrain->GetPassword();
if ( thePassword.empty() )
{
hBrain->SetPassword(hBrain->EncryptPassword(input);
brain->Send(hBrain->GetPassword());
brain->Send( "Ok.\n\r" );
}
else
{
if ( hBrain->VerifyPassword( input ) )
{
brain->Send( "Ok.\n\r\n\r" );
bool IBrainHuman::VerifyPassword( const string &password )
{
if(password == EncryptPassword(_password))
return true;
else
return false;
// return _password == password; /*EncryptPassword( password )*/
}
string IBrainHuman::EncryptPassword( const string &password )
{
return crypt( password.c_str(), name.c_str());
}
if (_password == EncryptPassword(password))
hBrain->SetPassword(hBrain->EncryptPassword(input); <— missing the closing ) for the call to SetPassword
This happens at login, simply taking a std::string and throwing it through crypt, then comparing the last saved crypted string to the one the user just entered. Im not sure how the second time I type the same word the string would be different, comparing the inputs works fine… cryping the inputs does not.