Skip to content

Commit

Permalink
Use Hash::isAcceptable to verify if hashed cast should hash the value
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Oct 17, 2023
1 parent a53227d commit e52fc3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ public static function encryptUsing($encrypter)
*/
protected function castAttributeAsHashedString($key, $value)
{
return $value !== null && Hash::needsRehash($value) ? Hash::make($value) : $value;
return $value !== null && ! Hash::isAcceptable($value) ? Hash::make($value) : $value;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/Database/EloquentModelHashedCastingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ protected function defineDatabaseMigrationsAfterDatabaseRefreshed()

public function testHashed()
{
$this->hasher->expects('needsRehash')
$this->hasher->expects('isAcceptable')
->with('this is a password')
->andReturnTrue();
->andReturnFalse();

$this->hasher->expects('make')
->with('this is a password')
Expand All @@ -49,11 +49,11 @@ public function testHashed()
]);
}

public function testNotHashedIfAlreadyHashed()
public function testNotHashedIfAlreadyCorrectlyHashed()
{
$this->hasher->expects('needsRehash')
$this->hasher->expects('isAcceptable')
->with('already-hashed-password')
->andReturnFalse();
->andReturnTrue();

$subject = HashedCast::create([
'password' => 'already-hashed-password',
Expand Down

0 comments on commit e52fc3f

Please sign in to comment.