2020use Illuminate \Support \Facades \Hash ;
2121use Illuminate \Support \Str ;
2222use Illuminate \Support \Traits \Macroable ;
23+ use InvalidArgumentException ;
2324use RuntimeException ;
2425use Symfony \Component \HttpFoundation \Request ;
2526use Symfony \Component \HttpKernel \Exception \UnauthorizedHttpException ;
@@ -581,16 +582,16 @@ protected function cycleRememberToken(AuthenticatableContract $user)
581582 * @param string $password
582583 * @param string $attribute
583584 * @return bool|null
585+ *
586+ * @throws \Illuminate\Auth\AuthenticationException
584587 */
585588 public function logoutOtherDevices ($ password , $ attribute = 'password ' )
586589 {
587590 if (! $ this ->user ()) {
588591 return ;
589592 }
590593
591- $ result = tap ($ this ->user ()->forceFill ([
592- $ attribute => Hash::make ($ password ),
593- ]))->save ();
594+ $ result = $ this ->rehashUserPassword ($ password , $ attribute );
594595
595596 if ($ this ->recaller () ||
596597 $ this ->getCookieJar ()->hasQueued ($ this ->getRecallerName ())) {
@@ -602,6 +603,26 @@ public function logoutOtherDevices($password, $attribute = 'password')
602603 return $ result ;
603604 }
604605
606+ /**
607+ * Rehash the current user's password.
608+ *
609+ * @param string $password
610+ * @param string $attribute
611+ * @return bool|null
612+ *
613+ * @throws \InvalidArgumentException
614+ */
615+ protected function rehashUserPassword ($ password , $ attribute )
616+ {
617+ if (! Hash::check ($ password , $ this ->user ()->{$ attribute })) {
618+ throw new InvalidArgumentException ("The given password does not match the current password. " );
619+ }
620+
621+ return tap ($ this ->user ()->forceFill ([
622+ $ attribute => Hash::make ($ password ),
623+ ]))->save ();
624+ }
625+
605626 /**
606627 * Register an authentication attempt event listener.
607628 *
0 commit comments