New: Add hidden option MAIN_SECURITY_HASH_ALGO to choose hash function

This commit is contained in:
Laurent Destailleur 2013-11-06 16:32:25 +01:00
parent ab668d1b26
commit 4a29431b69

View File

@ -69,21 +69,25 @@ function dol_decode($chain)
/**
* Returns a hash of a string
* Returns a hash of a string.
* If constant MAIN_SECURITY_HASH_ALGO is defined, we use this function as hashing function (md5 by default)
* If constant MAIN_SECURITY_SALT is defined, we use it as a salt
*
* @param string $chain String to hash
* @param int $type Type of hash (0:md5, 1:sha1, 2:sha1+md5)
* @param int $type Type of hash (0:auto, 1:sha1, 2:sha1+md5)
* @return string Hash of string
*/
function dol_hash($chain,$type=0)
{
global $conf;
// Salt value
if (! empty($conf->global->MAIN_SECURITY_SALT)) $chain=$conf->global->MAIN_SECURITY_SALT.$chain;
if ($type == 1) return sha1($chain);
else if ($type == 2) return sha1(md5($chain));
else if (! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1') return sha1($chain);
else if (! empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') return sha1(md5($chain));
else return md5($chain);
}