Skip to content

Commit b8fdfd0

Browse files
caseysoftwareclaude
andcommitted
Stop re-hashing the stored password when a user is saved again
CUser::hook_preUpdate() decided whether the password had changed by comparing the stored hash with a fresh password_hash() of the current value. Because password_hash() salts randomly they never matched, so any code path that loads a user and stores it again (without touching the password) hashed the existing hash and locked the user out. The LDAP authenticator does this on every login. Keep the stored hash when the value is empty or still equal to the stored hash, and hash it only when it is a new plain-text password. Refs #386 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CP89WVmGZ1VVCCZMS6ntN
1 parent 5b662e5 commit b8fdfd0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎modules/users/users.class.php‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ protected function hook_preUpdate() {
6060
$tmpUser->overrideDatabase($this->_query);
6161
$tmpUser->load($this->user_id);
6262

63-
if ('' == trim($this->user_password)) {
63+
// An empty password, or the stored hash itself (the object was loaded
64+
// and stored again), keeps the existing hash. Anything else is a new
65+
// plain-text password. Comparing against a fresh hash would always
66+
// differ because password_hash() salts randomly.
67+
$password = (string) $this->user_password;
68+
if ('' == trim($password) || $password === (string) $tmpUser->user_password) {
6469
$this->user_password = $tmpUser->user_password;
65-
} elseif ($tmpUser->user_password != $this->authenticator->hashPassword($this->user_password)) {
66-
$this->user_password = $this->authenticator->hashPassword($this->user_password);
6770
} else {
68-
$this->user_password = $tmpUser->user_password;
71+
$this->user_password = $this->authenticator->hashPassword($password);
6972
}
7073

7174
parent::hook_preUpdate();

0 commit comments

Comments
 (0)