48 return (function_exists(
'sha1') || function_exists(
'mhash'));
59 public function generate_hash (
string $pwd,
bool $locked = FALSE): string
61 if (function_exists(
'sha1')) {
62 $salt = substr(pack(
'h*', md5(random_int(0, PHP_INT_MAX))), 0, 8);
63 $salt = substr(pack(
'H*', sha1($salt.$pwd)), 0, 4);
64 $pwd =
'{SSHA}'.($locked ?
'!' :
'').base64_encode(pack(
'H*', sha1($pwd.$salt)).$salt);
65 } elseif (function_exists(
'mhash')) {
66 $salt = mhash_keygen_s2k(MHASH_SHA1, $pwd, substr(pack(
'h*', md5(random_int(0, PHP_INT_MAX))), 0, 8), 4);
67 $pwd =
'{SSHA}'.($locked ?
'!' :
'').base64_encode(mhash(MHASH_SHA1, $pwd.$salt).$salt);
74 function checkPassword ($pwd, $hash):
bool 76 $hash = base64_decode(substr($hash, 6));
77 $salt = substr($hash, 20);
78 $hash = substr($hash, 0, 20);
79 if (function_exists(
'sha1')) {
80 $nhash = pack(
'H*', sha1($pwd . $salt));
81 } elseif (function_exists(
'mhash')) {
82 $nhash = mhash(MHASH_SHA1, $pwd.$salt);
88 return ($nhash == $hash);
static get_hash_name()
Get the hash name.
__construct()
passwordMethodSsha Constructor
This class contains all the functions for ssha password method.
is_available()
Is available.
Parent class for all exceptions thrown in FusionDirectory.
static missingext($name)
Display about missing PHP extension.
This class contains all the basic function for password methods.
Parent class for all errors in FusionDirectory.
generate_hash(string $pwd, bool $locked=FALSE)
Generate template hash.