Habari\Utils::crypt PHP Méthode

crypt() public static méthode

Crypt a given password, or verify a given password against a given hash.
public static crypt ( string $password, string $hash = null ) : string | boolean
$password string the password to crypt or verify
$hash string (optional) if given, verify $password against $hash
Résultat string | boolean Encrypted password, or boolean for verification
    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'));
        }
    }