From d9bf6c432e2c28600ee5aa562f3f36f48cb7b7cc Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 27 Jun 2024 16:56:35 -0700 Subject: feat: Add method to validate an IHasher hash Signed-off-by: Christopher Ng --- lib/private/Security/Hasher.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/private/Security') diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php index 22e850157fc..081cac51161 100644 --- a/lib/private/Security/Hasher.php +++ b/lib/private/Security/Hasher.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'; + } } -- cgit v1.2.3