diff --git a/src/Illuminate/Auth/DatabaseUserProvider.php b/src/Illuminate/Auth/DatabaseUserProvider.php index 3f5f0ed55c27..f8005b7d14cd 100755 --- a/src/Illuminate/Auth/DatabaseUserProvider.php +++ b/src/Illuminate/Auth/DatabaseUserProvider.php @@ -152,14 +152,8 @@ protected function getGenericUser($user) */ public function validateCredentials(UserContract $user, array $credentials) { - $hashed = $user->getAuthPassword(); - - if (strlen($hashed) === 0) { - return false; - } - - return password_verify( - $credentials['password'], $hashed + return $this->hasher->check( + $credentials['password'], $user->getAuthPassword() ); } } diff --git a/src/Illuminate/Auth/EloquentUserProvider.php b/src/Illuminate/Auth/EloquentUserProvider.php index e9365a346292..23b5b792cf13 100755 --- a/src/Illuminate/Auth/EloquentUserProvider.php +++ b/src/Illuminate/Auth/EloquentUserProvider.php @@ -138,13 +138,8 @@ public function retrieveByCredentials(array $credentials) public function validateCredentials(UserContract $user, array $credentials) { $plain = $credentials['password']; - $hashed = $user->getAuthPassword(); - if (strlen($hashed) === 0) { - return false; - } - - return password_verify($plain, $hashed); + return $this->hasher->check($plain, $user->getAuthPassword()); } /** diff --git a/tests/Auth/AuthDatabaseUserProviderTest.php b/tests/Auth/AuthDatabaseUserProviderTest.php index 3ab5b5cbb975..f5f4f75a1798 100755 --- a/tests/Auth/AuthDatabaseUserProviderTest.php +++ b/tests/Auth/AuthDatabaseUserProviderTest.php @@ -115,22 +115,11 @@ public function testCredentialValidation() { $conn = m::mock('Illuminate\Database\Connection'); $hasher = m::mock('Illuminate\Contracts\Hashing\Hasher'); + $hasher->shouldReceive('check')->once()->with('plain', 'hash')->andReturn(true); $provider = new DatabaseUserProvider($conn, $hasher, 'foo'); $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); - $user->shouldReceive('getAuthPassword')->once()->andReturn('$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm'); - $result = $provider->validateCredentials($user, ['password' => 'secret']); - - $this->assertTrue($result); - } - - public function testCredentialValidationUsingUnknownAlgorithm() - { - $conn = m::mock('Illuminate\Database\Connection'); - $hasher = m::mock('Illuminate\Contracts\Hashing\Hasher'); - $provider = new DatabaseUserProvider($conn, $hasher, 'foo'); - $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); - $user->shouldReceive('getAuthPassword')->once()->andReturn('$1$0590adc6$WVAjBIam8sJCgDieJGLey0'); - $result = $provider->validateCredentials($user, ['password' => 's3cr3t']); + $user->shouldReceive('getAuthPassword')->once()->andReturn('hash'); + $result = $provider->validateCredentials($user, ['password' => 'plain']); $this->assertTrue($result); } diff --git a/tests/Auth/AuthEloquentUserProviderTest.php b/tests/Auth/AuthEloquentUserProviderTest.php index c58e4a9bb1ab..f5dab1acbab0 100755 --- a/tests/Auth/AuthEloquentUserProviderTest.php +++ b/tests/Auth/AuthEloquentUserProviderTest.php @@ -90,22 +90,11 @@ public function testCredentialValidation() { $conn = m::mock('Illuminate\Database\Connection'); $hasher = m::mock('Illuminate\Contracts\Hashing\Hasher'); + $hasher->shouldReceive('check')->once()->with('plain', 'hash')->andReturn(true); $provider = new EloquentUserProvider($hasher, 'foo'); $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); - $user->shouldReceive('getAuthPassword')->once()->andReturn('$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm'); - $result = $provider->validateCredentials($user, ['password' => 'secret']); - - $this->assertTrue($result); - } - - public function testCredentialValidationUsingUnknownAlgorithm() - { - $conn = m::mock('Illuminate\Database\Connection'); - $hasher = m::mock('Illuminate\Contracts\Hashing\Hasher'); - $provider = new EloquentUserProvider($hasher, 'foo'); - $user = m::mock('Illuminate\Contracts\Auth\Authenticatable'); - $user->shouldReceive('getAuthPassword')->once()->andReturn('$1$0590adc6$WVAjBIam8sJCgDieJGLey0'); - $result = $provider->validateCredentials($user, ['password' => 's3cr3t']); + $user->shouldReceive('getAuthPassword')->once()->andReturn('hash'); + $result = $provider->validateCredentials($user, ['password' => 'plain']); $this->assertTrue($result); }