Created
January 23, 2013 13:22
-
-
Save markuspoerschke/4605526 to your computer and use it in GitHub Desktop.
Simple hashing function in PHP. Any alogrithm supported by the build in hash() function can be used. This function actually only adds rounds and concatenate the string with a salt.
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
<?php | |
/** | |
* @param $string string The string/password to be hashed | |
* @param $salt string The salt that will be added to the string | |
* @param $rounds int Number of rounds | |
* @param $algo string The algorithm that should be used for hashing | |
* @return string Returns the hashed string | |
*/ | |
function createHash($string, $salt = '', $rounds = 500, $algo = 'sha256') { | |
for ($rounds; $rounds > 0; $rounds--) { | |
$string = hash($algo, $string . $salt); | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment