diff --git a/src/Illuminate/Auth/SessionGuard.php b/src/Illuminate/Auth/SessionGuard.php index 74569a7bf599..48d64c47d39f 100644 --- a/src/Illuminate/Auth/SessionGuard.php +++ b/src/Illuminate/Auth/SessionGuard.php @@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; +use InvalidArgumentException; use RuntimeException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; @@ -573,26 +574,6 @@ protected function cycleRememberToken(AuthenticatableContract $user) $this->provider->updateRememberToken($user, $token); } - /** - * Rehash the current user's password. - * - * @param string $password - * @param string $attribute - * @return bool|null - * - * @throws \Illuminate\Auth\AuthenticationException - */ - protected function rehashUserPassword($password, $attribute) - { - if (! Hash::check($password, $this->user()->$attribute)) { - throw new AuthenticationException('Password mismatch.'); - } - - return tap($this->user()->forceFill([ - $attribute => Hash::make($password), - ]))->save(); - } - /** * Invalidate other sessions for the current user. * @@ -622,6 +603,26 @@ public function logoutOtherDevices($password, $attribute = 'password') return $result; } + /** + * Rehash the current user's password. + * + * @param string $password + * @param string $attribute + * @return bool|null + * + * @throws \InvalidArgumentException + */ + protected function rehashUserPassword($password, $attribute) + { + if (! Hash::check($password, $this->user()->{$attribute})) { + throw new InvalidArgumentException("The given password does not match the current password."); + } + + return tap($this->user()->forceFill([ + $attribute => Hash::make($password), + ]))->save(); + } + /** * Register an authentication attempt event listener. * diff --git a/tests/Integration/Auth/AuthenticationTest.php b/tests/Integration/Auth/AuthenticationTest.php index 23862f48d94a..e2ec79050d18 100644 --- a/tests/Integration/Auth/AuthenticationTest.php +++ b/tests/Integration/Auth/AuthenticationTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Auth; -use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\EloquentUserProvider; use Illuminate\Auth\Events\Attempting; use Illuminate\Auth\Events\Authenticated; @@ -20,6 +19,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Testing\Fakes\EventFake; use Illuminate\Tests\Integration\Auth\Fixtures\AuthenticationTestUser; +use InvalidArgumentException; use Orchestra\Testbench\TestCase; /** @@ -225,8 +225,8 @@ public function testLoggingOutOtherDevices() public function testPasswordMustBeValidToLogOutOtherDevices() { - $this->expectException(AuthenticationException::class); - $this->expectExceptionMessage('Password mismatch.'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('current password'); $this->app['auth']->loginUsingId(1);