diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 150a3bd3feb..24227832370 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -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); }