Problems with crypt

Posted by Gaurnar on Thu 07 Jul 2005 09:54 AM — 14 posts, 44,364 views.

#0
I have encountered a problem with passwords.(I've compiled smaug1.4a under Cygwin) I can't login as Lordrom, because smaug tells that my password is incorrect. I tried looking into the code, and found the function "crypt" in charge of password comparing. What is that function and can it be responsible for that kind of problem?
Here is the part of the code where the password is being compared:
if ( strcmp( crypt( argument, ch->pcdata->pwd ),
ch->pcdata->pwd ) )
{
write_to_buffer( d, "Incorrect password.\n\r", 0 );
d->character->desc = NULL;
close_socket( d, FALSE );
return;
}

P.S: I didn't change anything in the code
USA #1
Do passwords work correctly otherwise? Like if you create a new character? If so, it is not a code problem and most likely it is just the incorrect password.
USA #2
There's some issue where the Windows crypt function simply returns the same password as what got typed, due to export law restrictions. E.g. crypt(hello) --> hello. If you're using Cygwin, the WIN32 preprocessor directive [i]might[/i] be defined and so it [i]might[/i] be falling back on the straight-through crypt. If that's the case, the Lordrom character might have an encrypted password stored, but crypt will never yield that password. Try changing the Lordrom password to the plaintext version and see if that works.
#3
to Zeno: I have the same problem with newly created characters, so I think that's the problem with crypt function.
USA #4
Might be. Try attaching gdb to it and printing the password of the character then print the argument.
#5
I tried printing password and argument and found out that they are equal! Can it be a strcmp function's error?
Though (while creating a new character) it says that the password I typed in to confirm is different from the password I typed in for the character, next time it seems to be allright! Look:

-- comments

---------------------------------
Make sure to use a password that won't be easily guessed by someone else.
Pick a good password for Max: qwerty

qwerty -- argument
qwerty -- password

Please retype the password to confirm: qwerty

qwerty -- argument
qwerty -- password
Passwords don't match.
Retype password:
qwerty -- argument
qwerty -- password

Please retype the password to confirm: qwerty --OK


Choose your sex: (M/F/N)
USA #6
What about printing a password in crypt? Or you can try using the 'formpass' command on the MUD.
#7
I have rewritten the code, so I don't use crypt anymore. But still it doesn't work, and I can't get the idea why.
Here's the code:
---------
case CON_GET_NEW_PASSWORD:
write_to_buffer( d, "\n\r", 2 );

if ( strlen(argument) < 5 )
{
write_to_buffer( d,
"&#1055;&#1072;&#1088;&#1086;&#1083;&#1100; &#1076;&#1086;&#1083;&#1078;&#1077;&#1085; &#1089;&#1086;&#1076;&#1077;&#1088;&#1078;&#1072;&#1090;&#1100; &#1087;&#1086; &#1082;&#1088;&#1072;&#1081;&#1085;&#1077;&#1081; &#1084;&#1077;&#1088;&#1077; 5 &#1089;&#1080;&#1084;&#1074;&#1086;&#1083;&#1086;&#1074;.\n\r&#1055;&#1072;&#1088;&#1086;&#1083;&#1100;: ", // it's some Russian
0 );
return;
}

pwdnew = argument;
for ( p = pwdnew; *p != '\0'; p++ )
{
if ( *p == '~' )
{
write_to_buffer( d,
"&#1053;&#1077;&#1087;&#1088;&#1080;&#1077;&#1084;&#1083;&#1077;&#1084;&#1099;&#1081; &#1087;&#1072;&#1088;&#1086;&#1083;&#1100;.\n\r&#1055;&#1072;&#1088;&#1086;&#1083;&#1100;: ",
0 );
return;
}
}
DISPOSE( ch->pcdata->pwd );
ch->pcdata->pwd = str_dup( pwdnew );
write_to_buffer( d, "\n\rPlease retype the password to confirm: ", 0 );
d->connected = CON_CONFIRM_NEW_PASSWORD;
break;

case CON_CONFIRM_NEW_PASSWORD:
write_to_buffer( d, "\n\r", 2 );

if (strcmp(argument, ch->pcdata->pwd ))
{
write_to_buffer( d, "Passwords don't match.\n\rRetype password: ",
0 );
d->connected = CON_GET_NEW_PASSWORD;
return;
}
-------
Please, help me!
USA #8
What's wrong? They don't match? Try printing argument and ch->password->pwd
#9
Finally, I've got the idea. Could you please tell me some alternatives for isascii and isprint functions, the problem is that they don't support letters of Russian alphabet. I tried iswascii, but there is no such function declared in Cygwin. When I tried to remove these functions from the code, the problem with passwords occured. Here is the piece of the code that is malfunctioning with letters of Russian alphabet:
------------------------
if ( d->inbuf[i] == '\b' && k > 0 )
--k;
else if ( isascii(d->inbuf[i]) && isprint(d->inbuf[i]) )
d->incomm[k++] = d->inbuf[i];
USA #10
Bit late to the table here, but did you try downloading the Cygwin crypt library? It's in the development or library sections listed as libcrypt and probably would have solved your problem with minimal hassle.

The other alternative would have been to install the MD5 password snippet which doesn't require the use of any crypt libraries and would also likely have solved the problem.

If it's due to the code not accepting Russian characters, there's a line in the comm.c file ( don't know off hand exactly where ) that makes a call to isprint() and can be modified to allow what you need.
#11
2Samson: What do you mean by "modify" the line with isprint in it? How should I change it?
Speaking about crypt, I'm using a NOCRYPT define in the source, so it should work fine, but it doesn't.
USA #12
Look over "man isprint" for what it checks and if it allows Russian characters. If it doesn't, remove the check.
#13
Yeah, it doesn't allow Russian characters, but if I remove it I get the problem with the passwords, which I told you about before. Even in that case SMAUG doesn't support Russian characters, though I know for certain that there's a way for making him support them, because in Russia we have a MUD game based on SMAUG that is in Russian. Help me!