feat: Add method to validate an IHasher hash

Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
Christopher Ng 2024-06-27 16:56:35 -07:00
parent 7e8a061ab6
commit d9bf6c432e
2 changed files with 21 additions and 0 deletions

View file

@ -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';
}
}

View file

@ -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;
}