Set password to postfix email users stored in mysql by php -
i developing server control panel, haven't been able set correctly user password in mysql database.
the mysql query used store password following:
encrypt('firstpassword', concat('$6$', substring(sha(rand()), -16)))
yet, haven't been able replicate result in php (of cource, using static salt): don't match.
here's php code have been working with:
$salt = '1234567890123456'; $password = 'hello'; $hexhash = hash('sha512', '$6$'. $salt); // bda6a11cc3aa00b8fe46f0559e86b3e4be3a6646f7dca2df29da1db86cfd7fc0ceb9ca076d16f0296b82e120170f08e049f607cc6e2d7328976f8cb4e8cacf98 $binhash = hex2bin($hexhash); $hash = base64_encode($binhash); // vaahhmoqalj+rvbvnoaz5l46zkb33klfkdodugz9f8doucohbrbwkwuc4saxdwjgsfyhzg4tcyixb4y06mrpma==
the password instead should 12nkz5xm5jeki
. clues why mysql , php implementations differ?
found out that, contrary i've found looking on google (some people tried use sha512 hash), mysql encrypt
function uses plain unix crypt
library, trivial implement in php.
here's code:
$password = 'firstpassword'; $salt = '$6$' . '6bfd195afba021a2'; // or, if want random version, $password = 'firstpassword'; $salt = '$6$' . substr(md5(microtime()),16); // , generation echo crypt($password, $salt);
it sad on internet there code, , that's why i've shared :)
Comments
Post a Comment