md5 crypt question

From: Date: Tue, 17 Jul 2001 16:28:55 +0000
Subject: md5 crypt question
Groups: php.general 
Request: Send a blank email to php-general+get-58293@lists.php.net to get a copy of this message
I'd like to use php to do what I'm able to do in perl. use String::Random; use Crypt::PasswdMD5; $foo = new String::Random; $rand = $foo->randpattern("ss"); print "Type in your password: "; $password = <STDIN>; $hash = unix_md5_crypt($password,$rand); $salt = substr($hash,3,2); print "SUBSTR: $salt\n"; print "HASH: $hash\n"; print "SALT: $rand\n"; print "Type in your password: "; $password_verify = <STDIN>; $hash_verify = unix_md5_crypt($password_verify,$salt); if ($hash eq $hash_verify) { print "Good to go!\n"; print "HASH BEFORE: $hash\n"; print "HASH AFTER: $hash_verify\n"; } else { print "You fuckered it up!\n"; print "HASH BEFORE: $hash\n"; print "HASH AFTER: $hash_verify\n"; } srv1:~$ ./crypt.pl Type in your password: password SUBSTR: Kd HASH: $1$Kd$T9I3jUnJvGy0Ekfg2VobM0 SALT: Kd Type in your password: password Good to go! HASH BEFORE: $1$Kd$T9I3jUnJvGy0Ekfg2VobM0 HASH AFTER: $1$Kd$T9I3jUnJvGy0Ekfg2VobM0 I've looked at crypt() in php and it claims that if you pass it a salt that resembles $1$ format, it should generate an md5 type hash, but this doesn't seem to be the case for me. The crypt only looks at the first two characters of the salt, no matter what, so my salt never changes because it just seems $1. Thanks for explaining what I'm doing wrong. -jeremy -- salad.

« previous php.general (#58293) next »