aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Security
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2024-06-27 16:56:35 -0700
committerChristopher Ng <chrng8@gmail.com>2024-07-04 17:05:45 -0700
commitd9bf6c432e2c28600ee5aa562f3f36f48cb7b7cc (patch)
tree1b42bebb1e362aaad28a15b73872552da1655332 /lib/private/Security
parent7e8a061ab6a4aed213440503b8cb919468eff4cc (diff)
downloadnextcloud-server-d9bf6c432e2c28600ee5aa562f3f36f48cb7b7cc.tar.gz
nextcloud-server-d9bf6c432e2c28600ee5aa562f3f36f48cb7b7cc.zip
feat: Add method to validate an IHasher hash
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private/Security')
-rw-r--r--lib/private/Security/Hasher.php14
1 files changed, 14 insertions, 0 deletions
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';
+ }
}