From 1800525b51468c6d8b20a66562c9da71951d408f Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 4 Aug 2017 00:31:35 +0200 Subject: [PATCH] Implement new method 'changePasswordWithoutOldPassword' in 'Auth' --- src/Auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index 7d1446f..600026a 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -638,6 +638,26 @@ final class Auth extends UserManager { } } + /** + * Changes the currently signed-in user's password without requiring the old password for verification + * + * @param string $newPassword the new password that should be set + * @throws NotLoggedInException if the user is not currently signed in + * @throws InvalidPasswordException if the desired new password has been invalid + * @throws AuthError if an internal problem occurred (do *not* catch) + */ + public function changePasswordWithoutOldPassword($newPassword) { + if ($this->isLoggedIn()) { + $newPassword = self::validatePassword($newPassword); + $userId = $this->getUserId(); + $this->updatePassword($userId, $newPassword); + $this->deleteRememberDirective($userId); + } + else { + throw new NotLoggedInException(); + } + } + /** * Updates the given user's password by setting it to the new specified password *