Skip to content

Commit 3b2183e

Browse files
committed
Avoid using the same password as old/new. Improving messages
1 parent 2dde941 commit 3b2183e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/Controller/Traits/PasswordManagementTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function changePassword()
6363
} catch (UserNotFoundException $exception) {
6464
$this->Flash->error(__d('Users', 'User was not found'));
6565
} catch (WrongPasswordException $wpe) {
66-
$this->Flash->error(__d('Users', 'The current password does not match'));
66+
$this->Flash->error(__d('Users', '{0}', $wpe->getMessage()));
6767
} catch (Exception $exception) {
6868
$this->Flash->error(__d('Users', 'Password could not be changed'));
6969
}

src/Model/Behavior/PasswordBehavior.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public function changePassword(EntityInterface $user)
117117

118118
if (!empty($user->current_password)) {
119119
if (!$user->checkPassword($user->current_password, $currentUser->password)) {
120-
throw new WrongPasswordException(__d('Users', 'The old password does not match'));
120+
throw new WrongPasswordException(__d('Users', 'The current password does not match'));
121+
}
122+
if ($user->current_password === $user->password_confirm) {
123+
throw new WrongPasswordException(__d('Users', 'You cannot use the current password as the new one'));
121124
}
122125
}
123126
$user = $this->_table->save($user);

0 commit comments

Comments
 (0)