Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 16, 2021
1 parent 7aabd8f commit 1e61612
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
41 changes: 21 additions & 20 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1e61612

Please sign in to comment.