diff --git a/verify.php b/verify.php index 4d72e02..f72f1ba 100644 --- a/verify.php +++ b/verify.php @@ -349,4 +349,30 @@ class verify return true; } + /** Return true if the provided string is a valid hash + * @param string $algo The hash algo to test + * @param string $val The value to test + */ + public function isHash ($algo, $val) + { + return \verify::IsHash ($algo, $val); + } + + /** Return true if the provided string is a valid hash in static + * @param string $algo The hash algo to test + * @param string $val The value to test + */ + public static function staticIsHash ($algo, $val) + { + if (! is_string ($algo) || ! is_string ($val)) + return false; + if (! in_array ($algo, hash_algos ())) + throw new \Exception ("Unknown algo provided to verify the hash", 500); + $len = strlen (hash ($algo, "")); + if (strlen ($val) !== $len) + return false; + if (\verify::staticIsAllowedChars ($val, "0123456789abcdef") === false) + return false; + return true; + } }