Skip to content

Instantly share code, notes, and snippets.

@markuspoerschke
Created January 23, 2013 13:22
Show Gist options
  • Save markuspoerschke/4605526 to your computer and use it in GitHub Desktop.
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.
<?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