Crypt! :)

Posted by Vermithrax on Wed 27 Aug 2003 10:17 PM — 4 posts, 18,995 views.

USA #0
Hey folks... I've been staring at the crypt code for a while, and I see
this in do_password:

if ( strcmp( crypt( arg1, ch->pcdata->pwd ), ch->pcdata->pwd ) )
{
wait_state( ch, 40 );
send_to_char( "Wrong password. Wait 10 seconds.\n\r", ch );
return;
}

So anyhow...

Why in the world are we doing a crypt of arg1 (what you type in for the new
password) and ch->pcdata->pwd??? Isn't ch->pcdata->pwd your password
already encrypted?? Why wouldn't you do a crypt of arg1 and the character's
name and compare it with ch->pcdata->pwd? Can someone explain that, please?

-Verm
USA #1
I believe it crypts arg1 to compage it against the current password to see if they are the same. Same thing could be done by decrypting ch->pcdata->pwd. Anyways, I think thats right, or thats how I understand it. You might wait for a response from someone like Gammon, Boborak, Samson, or someone that knows this a bit more then I do.
USA #2
Actually, I have it totally figured out now. :) Cool beans, thanks in advance! :)
USA #3
Glad you figured it out ;-) For future refrence though, here's how it works.

When a new player is created, the password they supply is ran through the crypt function with their name like so:

crypt("password","Boborak")

Which returns the encrypted 'key' = BodDv430F5Nhs

That key is stored as the players 'password' in ch->pcdata->pwd

Now when the player logs on again and he enters his cleartext password 'password', the mud then takes the crypt() function again and checks the 'key' against the password like so:

crypt("password", "BodDv430F5Nhs")

This will return the exact same 'key' = BodDv430F5Nhs

Since it matches what's stored in ch->pcdata->pwd, the password must be correct.

This can be further demonstrated using the command 'formpass'.

Doing:
'formpass password Boborak' gives you the same as 'formpass password BodDv430F5Nhs'

Nifty eh? ;-)

-Boborak