Skip to content

Commit 18b9bad

Browse files
authored
[11.x] Fix Bcrypt/Argon/Argon2I Hashers not checking database field for nullish value before checking hash compatibility (#52297)
* Fix Bcrypt Hasher not checking database field for nullish value Updates Bcrypt Hasher implementation to correctly check if the `$hashedValue` field being checked for Hash Algorithm compatibility is not `null` or of length `0`. This gives us the behavior before hash verification was added to the framework that will trigger the framework to return early with a proper response of `false` as opposed to a generic `RuntimeException` being thrown for a value that should never have been checked for hash algorithm compatibility * Update ArgonHasher to check for nullish value before hash compatibility check * Update Argon2IdHasher to check for nullish value before hash compatibility
1 parent ecfb547 commit 18b9bad

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Illuminate/Hashing/Argon2IdHasher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class Argon2IdHasher extends ArgonHasher
1818
*/
1919
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
2020
{
21-
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
22-
throw new RuntimeException('This password does not use the Argon2id algorithm.');
23-
}
24-
2521
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
2622
return false;
2723
}
24+
25+
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
26+
throw new RuntimeException('This password does not use the Argon2id algorithm.');
27+
}
2828

2929
return password_verify($value, $hashedValue);
3030
}

src/Illuminate/Hashing/ArgonHasher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ protected function algorithm()
9595
*/
9696
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
9797
{
98+
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
99+
return false;
100+
}
101+
98102
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
99103
throw new RuntimeException('This password does not use the Argon2i algorithm.');
100104
}

src/Illuminate/Hashing/BcryptHasher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function make(#[\SensitiveParameter] $value, array $options = [])
6767
*/
6868
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
6969
{
70+
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
71+
return false;
72+
}
73+
7074
if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
7175
throw new RuntimeException('This password does not use the Bcrypt algorithm.');
7276
}

0 commit comments

Comments
 (0)