Skip to content

Instantly share code, notes, and snippets.

@jas-
Created June 21, 2011 16:22
Show Gist options
  • Save jas-/1038226 to your computer and use it in GitHub Desktop.
Save jas-/1038226 to your computer and use it in GitHub Desktop.
PHP salter
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));
}
@jas-
Copy link
Author

jas- commented Jun 22, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment