mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
feat: Add method to validate an IHasher hash
Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
7e8a061ab6
commit
d9bf6c432e
2 changed files with 21 additions and 0 deletions
|
|
@ -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…
Reference in a new issue