verify: check hashes
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3754 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
26
verify.php
26
verify.php
@@ -349,4 +349,30 @@ class verify
|
|||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user