aboutsummaryrefslogtreecommitdiffstats
path: root/lib
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
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')
-rw-r--r--lib/private/Security/Hasher.php14
-rw-r--r--lib/public/Security/IHasher.php7
2 files changed, 21 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';
+ }
}
diff --git a/lib/public/Security/IHasher.php b/lib/public/Security/IHasher.php
index 378c2cf3f51..d985ffe48ab 100644
--- a/lib/public/Security/IHasher.php
+++ b/lib/public/Security/IHasher.php
@@ -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;
}