Created
August 14, 2011 19:29
-
-
Save xqus/1145215 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Inject a salt into a password to create the string to be hashed. | |
* @author Audun Larsen <[email protected]> | |
* | |
* @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