public static function crypt($password, $hash = null)
{
if ($hash == null) {
return self::ssha512($password, $hash);
// This line should always reflect the best algorithm at the time
} elseif (strlen($hash) > 3) {
// need at least {, } and a char :p
// verify
if ($hash[0] == '{') {
// new hash from the block
$algo = strtolower(substr($hash, 1, strpos($hash, '}', 1) - 1));
switch ($algo) {
case 'sha1':
case 'ssha':
case 'ssha512':
case 'md5':
return self::$algo($password, $hash);
default:
Error::raise(_t('Unsupported digest algorithm "%s"', array($algo)));
return false;
}
} else {
// legacy sha1
return sha1($password) == $hash;
}
} else {
Error::raise(_t('Invalid hash'));
}
}