Skip to content

Commit

Permalink
Update DatabaseTokenRepository.php
Browse files Browse the repository at this point in the history
  • Loading branch information
HSPDev authored Dec 18, 2016
1 parent cd0396f commit c454c87
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class DatabaseTokenRepository implements TokenRepositoryInterface
Expand Down Expand Up @@ -36,7 +37,14 @@ class DatabaseTokenRepository implements TokenRepositoryInterface
* @var int
*/
protected $expires;


/**
* The hasher implementation.
*
* @var \Illuminate\Contracts\Hashing\Hasher
*/
protected $hasher;

/**
* Create a new token repository instance.
*
Expand All @@ -46,12 +54,13 @@ class DatabaseTokenRepository implements TokenRepositoryInterface
* @param int $expires
* @return void
*/
public function __construct(ConnectionInterface $connection, $table, $hashKey, $expires = 60)
public function __construct(ConnectionInterface $connection, HasherContract $hasher, $table, $hashKey, $expires = 60)
{
$this->table = $table;
$this->hashKey = $hashKey;
$this->expires = $expires * 60;
$this->connection = $connection;
$this->hasher = $hasher;
}

/**
Expand Down Expand Up @@ -96,7 +105,7 @@ protected function deleteExisting(CanResetPasswordContract $user)
*/
protected function getPayload($email, $token)
{
return ['email' => $email, 'token' => $token, 'created_at' => new Carbon];
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new Carbon];
}

/**
Expand All @@ -106,13 +115,13 @@ protected function getPayload($email, $token)
* @param string $token
* @return bool
*/
public function exists(CanResetPasswordContract $user, $token)
public function exists(CanResetPasswordContract $user, $userToken)
{
$email = $user->getEmailForPasswordReset();

$token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first();
$token = (array) $this->getTable()->where('email', $email)->first();

return $token && ! $this->tokenExpired($token);
return $token && ! $this->tokenExpired($token) && $this->hasher->check($userToken, $token['token']);
}

/**
Expand Down

0 comments on commit c454c87

Please sign in to comment.