Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix deprecation warning when comparing a password against a NULL database password #44986

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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