feat: Add method to validate an IHasher hash

Signed-off-by: Christopher Ng <chrng8@gmail.com>
pull/46186/head
Christopher Ng 2 years ago
parent 7e8a061ab6
commit d9bf6c432e
  1. 14
      lib/private/Security/Hasher.php
  2. 7
      lib/public/Security/IHasher.php

@ -190,4 +190,18 @@ class Hasher implements IHasher {
return $default;
}
public function validate(string $prefixedHash): bool {
$splitHash = $this->splitHash($prefixedHash);
if (empty($splitHash)) {
return false;
}
$validVersions = [3, 2, 1];
$version = $splitHash['version'];
if (!in_array($version, $validVersions, true)) {
return false;
}
$algoName = password_get_info($splitHash['hash'])['algoName'];
return $algoName !== 'unknown';
}
}

@ -47,4 +47,11 @@ interface IHasher {
* @since 8.0.0
*/
public function verify(string $message, string $hash, &$newHash = null): bool ;
/**
* Check if the prefixed hash is valid
*
* @since 30.0.0
*/
public function validate(string $prefixedHash): bool;
}

Loading…
Cancel
Save