Created
June 21, 2011 16:22
-
-
Save jas-/1038226 to your computer and use it in GitHub Desktop.
PHP salter
This file contains 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
function _salt($string, $len=null) | |
{ | |
return (!empty($len)) ? | |
hash('sha512', str_pad($string, (strlen($string) + $len), | |
substr(hash('sha512', $string), | |
round((float)strlen($string)/3, 0, | |
PHP_ROUND_HALF_UP), | |
($len - strlen($string))), | |
STR_PAD_BOTH)) : | |
hash('sha512', substr($string, | |
round((float)strlen($string)/3, 0, | |
PHP_ROUND_HALF_UP), 16)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses unique string and length of desired output as arguments.
If string argument is lower then desired output length, the string gets hashed, padded with a divisible return of another hash of the string argument or it will return the hashed portion of the original string argument as a 16 character salt.