11 Nov, 2010, balakoth wrote in the 1st comment:
Votes: 0
Alright, so Ive tried using the crypt function two different ways. While checking a password using either a static string as the key, or the login name, the second time (lets say creating a new character) it asks for the password, the crypted string is different.

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.

Enter password: putter

$1$zetyadr$JCDh0KnvKiHLmRy/e55VJ.

Password Acceptable.

Enter password: putter

$1$zetyadr$dD.45Ux1mmZ4i8N1v0FUR.

Passwords do not match.

2 more chances.
12 Nov, 2010, Tyche wrote in the 2nd comment:
Votes: 0
I would guess that are using a different 'salt' each time you call crypt.
12 Nov, 2010, balakoth wrote in the 3rd comment:
Votes: 0
Well I was thinking maybe the name was changing.. but even if I use the same 'salt' a static string I know is not changing. It still does waht it wants..

The only thing I can think of is that my input is being changed some how, but in my attempts to display the input it still shows it as correct
12 Nov, 2010, quixadhal wrote in the 4th comment:
Votes: 0
crypt() probably doesn't take a std::string, it almost certainly takes a char *. Try using variable.c_str().
12 Nov, 2010, balakoth wrote in the 5th comment:
Votes: 0
Yes I am aware. This error is occuring with the string.c_str() method
12 Nov, 2010, Kaz wrote in the 6th comment:
Votes: 0
What's your code for encrypting here?
12 Nov, 2010, balakoth wrote in the 7th comment:
Votes: 0
Ive since tried doing non encrypted strings, so.. unfortunately I have a feeling the problem lies deeper than that library call.. but most along the lines of my input being parsed wrong, or im not flushing it correctly after a send
12 Nov, 2010, Davion wrote in the 8th comment:
Votes: 0
balakoth said:
Ive since tried doing non encrypted strings, so.. unfortunately I have a feeling the problem lies deeper than that library call.. but most along the lines of my input being parsed wrong, or im not flushing it correctly after a send


The problem is probably far more superficial then you think ;). However, it's impossible for any of us to come to an absolute conclusion without any code to work with ;)
12 Nov, 2010, quixadhal wrote in the 9th comment:
Votes: 0
balakoth said:
Yes I am aware. This error is occuring with the string.c_str() method


I find that hard to believe, since std::string has been well tested by millions of people across dozens of platforms for about 20 years now. As Davion said, without seeing your code all we can do is guess. To me, it sounds like you are passing the std::string object into crypt() via a cast, in which case it would treat the internal std::string overhead (pointers, size, etc) as part of the char * array, and THAT would make them different even if the content were identical.

#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


Soooooo… what are you doing different from that?
13 Nov, 2010, balakoth wrote in the 10th comment:
Votes: 0
Ill post some code here in a min (one with the read descriptor function too) But im not doing anything different than that..

I phrased my last post wrong.. its not that the error is coming from c_str method. Not even sure what I was trying to type at that point lol.

Simply comparing a std::string password to std::string password is not accepting it as a match which is where I was assuming I may ahve something screwy going on my Input Reading.

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" );


Functions in IBrain

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());
}
13 Nov, 2010, ocson wrote in the 11th comment:
Votes: 0
It looks like you reversed your variables in your VerifyPassword method

Shouldn't line 5 be:

if (_password == EncryptPassword(password))


as your comment seems to indicate.
06 Dec, 2010, andril wrote in the 12th comment:
Votes: 0
Also:
hBrain->SetPassword(hBrain->EncryptPassword(input); <— missing the closing ) for the call to SetPassword
0.0/12