Skip to content

Commit

Permalink
Check for null and return false
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGiting committed Nov 17, 2022
1 parent 22c2cee commit 939302c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Hashing/AbstractHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function info($hashedValue)
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param string|null $hashedValue
* @param array $options
* @return bool
*/
public function check($value, $hashedValue, array $options = [])
{
if (strlen($hashedValue) === 0) {
if (is_null($hashedValue)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Hashing/Argon2IdHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Argon2IdHasher extends ArgonHasher
* Check the given plain value against a hash.
*
* @param string $value
* @param string $hashedValue
* @param string|null $hashedValue
* @param array $options
* @return bool
*
Expand All @@ -22,7 +22,7 @@ public function check($value, $hashedValue, array $options = [])
throw new RuntimeException('This password does not use the Argon2id algorithm.');
}

if (strlen($hashedValue) === 0) {
if (is_null($hashedValue)) {
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Hashing/HasherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@

class HasherTest extends TestCase
{
public function testEmptyHashedValueReturnsFalse()
{
$hasher = new BcryptHasher();
$this->assertTrue($hasher->check('password', ''));
$hasher = new ArgonHasher();
$this->assertTrue($hasher->check('password', ''));
$hasher = new Argon2IdHasher();
$this->assertTrue($hasher->check('password', ''));
}

public function testNullHashedValueReturnsFalse()
{
$hasher = new BcryptHasher();
$this->assertTrue($hasher->check('password', null));
$hasher = new ArgonHasher();
$this->assertTrue($hasher->check('password', null));
$hasher = new Argon2IdHasher();
$this->assertTrue($hasher->check('password', null));
}

public function testBasicBcryptHashing()
{
$hasher = new BcryptHasher;
Expand Down

0 comments on commit 939302c

Please sign in to comment.