crypt() problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
miro
Forum Newbie
Posts: 2
Joined: Mon Jul 01, 2002 1:38 pm

crypt() problems

Post by miro »

Hi,

I am trying to encrypt a string using DES (yes, I know it's insecure, but I need to use it for compatibility with my MUD's savefiles). If I do a call like this:

$encrypted = crypt($login_pass, substr($login_pass, 0, 2));

$encrypted is equal to the salt plus some encrypted string.

This isn't a bug with the crypt() function on my system, as this all works fine from C. I suspect it has something to do with how I'm passing the arguments.

Thank you for any help.
User avatar
martin
Forum Commoner
Posts: 33
Joined: Fri Jun 28, 2002 12:59 pm
Location: Cambridgeshire

Post by martin »

Are you sure $login_pass has a value, try echoing it out before your crypt call to make sure it's set.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

problem?

Post by llimllib »

As far as I can see, the function works in PHP exactly as it does in Cygwin's crypt() function, i.e:
$login_pass = "doggie";
$salt = substr($login_pass, 0, 2);
$encrypted = crypt($login_pass, $salt);
print $encrypted
yields the same as
crypt do doggie
does in Cygwin. both return do4L9dKP87bPQ
User avatar
allevon
Forum Newbie
Posts: 11
Joined: Mon Jul 01, 2002 10:42 am
Location: USA

Post by allevon »

I think this may help:

$Password = substr(md5("phpcryptcamp".$Password),0,10);
miro
Forum Newbie
Posts: 2
Joined: Mon Jul 01, 2002 1:38 pm

Post by miro »

Ahh, I see... I haven't been using crypt() correctly at all (the way that my MUD stores passwords is way different than how I thought they did). So looks like the fault was on my end. :wink:

But thanks y'all for your help. :)
Post Reply