7if (version_compare(PHP_VERSION,
'5.5.0',
'<') && (version_compare(PHP_VERSION,
'5.3.7',
'>=') || defined(
'PHP53_BCRYPT_Y2_FIXED'))) {
13 private bool $useNativeHashing =
false;
15 public function User_EncryptPassword(&$controller)
22 parent::__construct($controller);
23 $this->useNativeHashing = (function_exists(
'password_hash') && function_exists(
'password_needs_rehash'));
28 $this->mController->mRoot->mDelegateManager->add(
'User.EncryptPassword', [$this,
'encryptPassword']);
29 $this->mController->mRoot->mDelegateManager->add(
'User.PasswordVerify', [$this,
'passwordVerify']);
30 $this->mController->mRoot->mDelegateManager->add(
'User.PasswordNeedsRehash', [$this,
'needsRehash']);
33 public function encryptPassword(&$password)
36 if ($this->useNativeHashing) {
37 $password = password_hash($input, PASSWORD_DEFAULT);
39 $password = md5($input);
43 public function passwordVerify(&$result, $password, $hash)
46 if (32 === strlen($hash)) {
47 $result = md5($password) === $hash;
48 }
else if ($this->useNativeHashing) {
49 $result = password_verify($password, $hash);
53 public function needsRehash(&$needs, $val)
55 if ($this->useNativeHashing) {
56 $needs = password_needs_rehash($val, PASSWORD_DEFAULT);
59 $needs = 32 !== strlen($val);