Skip to content

Instantly share code, notes, and snippets.

@xqus
Created August 14, 2011 19:29
Show Gist options
  • Save xqus/1145215 to your computer and use it in GitHub Desktop.
Save xqus/1145215 to your computer and use it in GitHub Desktop.
<?php
/**
* Inject a salt into a password to create the string to be hashed.
* @author Audun Larsen <larsen@xqus.com>
*
* @param string $password
* Plain-text password.
*
* @param string $salt
* Well, the salt to inject into the password.
*
* @return string
* Returns the salted password, ready to be hashed.
*/
function pwInject($password, $salt) {
$hex = hexdec(substr(hash('sha256', $password), 0, 1));
$len = strlen($password);
$pos = floor($hex*($len/16));
return substr($password, 0, $pos).$salt.substr($password, $pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment