Skip to content

Instantly share code, notes, and snippets.

@bizmate
Last active August 29, 2015 14:22
Show Gist options
  • Save bizmate/2cc7a91f6536196a4918 to your computer and use it in GitHub Desktop.
Save bizmate/2cc7a91f6536196a4918 to your computer and use it in GitHub Desktop.
Symfony sha512 encoder
<?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