Last active
August 29, 2015 14:22
-
-
Save bizmate/2cc7a91f6536196a4918 to your computer and use it in GitHub Desktop.
Symfony sha512 encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
the below is a semplification of | |
https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php#L44 | |
*/ | |
echo "\n\n" . encodePassword('Password1', 'ghka3jtwknsck4wsgs0kwwos44oswgc') . "\n\n"; | |
function encodePassword($raw, $salt) | |
{ | |
$salted = $raw.'{'.$salt.'}'; | |
$digest = hash('sha512', $salted, true); echo 'Salted : ' . $salted . ' salt: ' . $salt . ' iterations: ' . 5000 . "\n\n"; //die; | |
// "stretch" hash | |
for ($i = 1; $i < 5000; ++$i) { | |
$digest = hash('sha512', $digest.$salted, true); | |
} | |
return true ? base64_encode($digest) : bin2hex($digest); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment