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
HASH: $1$Kd$T9I3jUnJvGy0Ekfg2VobM0
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.



PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to