Skip to content
Snippets Groups Projects
Verified Commit 00a619f3 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3305807 by andypost, ChrisPerko, mediabounds, xjm, sorlov, Rishabh...

Issue #3305807 by andypost, ChrisPerko, mediabounds, xjm, sorlov, Rishabh Vishwakarma, ilya.no, asad_ahmed, paulocs, Michelle, _pratik_, reenaraghavan, DanChadwick, smustgrave, larowlan, allisonherodevs: Password is null if user has never logged in which causes PHP 8 warning
parent 9f4e89ed
No related branches found
No related tags found
Loading
...@@ -27,8 +27,8 @@ public function hash(#[\SensitiveParameter] $password); ...@@ -27,8 +27,8 @@ public function hash(#[\SensitiveParameter] $password);
* Check whether a plain text password matches a hashed password. * Check whether a plain text password matches a hashed password.
* *
* @param string $password * @param string $password
* A plain-text password * A plain-text password.
* @param string $hash * @param string|null $hash
* A hashed password. * A hashed password.
* *
* @return bool * @return bool
...@@ -46,7 +46,7 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $ ...@@ -46,7 +46,7 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $
* This method returns TRUE if the password was hashed with an older * This method returns TRUE if the password was hashed with an older
* algorithm. * algorithm.
* *
* @param string $hash * @param string|null $hash
* The hash to be checked. * The hash to be checked.
* *
* @return bool * @return bool
......
...@@ -45,6 +45,10 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $ ...@@ -45,6 +45,10 @@ public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $
if (strlen($password) > static::PASSWORD_MAX_LENGTH) { if (strlen($password) > static::PASSWORD_MAX_LENGTH) {
return FALSE; return FALSE;
} }
// Newly created accounts may have empty passwords.
if ($hash === NULL || $hash === '') {
return FALSE;
}
return password_verify($password, $hash); return password_verify($password, $hash);
} }
......
...@@ -242,6 +242,10 @@ public function hash(#[\SensitiveParameter] $password) { ...@@ -242,6 +242,10 @@ public function hash(#[\SensitiveParameter] $password) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $hash) { public function check(#[\SensitiveParameter] $password, #[\SensitiveParameter] $hash) {
// Newly created accounts may have empty passwords.
if ($hash === NULL || $hash === '') {
return FALSE;
}
if (substr($hash, 0, 2) == 'U$') { if (substr($hash, 0, 2) == 'U$') {
// This may be an updated password from user_update_7000(). Such hashes // This may be an updated password from user_update_7000(). Such hashes
// have 'U' added as the first character and need an extra md5() (see the // have 'U' added as the first character and need an extra md5() (see the
......
...@@ -114,4 +114,14 @@ public function testPasswordRehashing() { ...@@ -114,4 +114,14 @@ public function testPasswordRehashing() {
$this->assertTrue($this->passwordHasher->check($this->password, $rehashed_password), 'Password check succeeds with re-hashed password with original hasher.'); $this->assertTrue($this->passwordHasher->check($this->password, $rehashed_password), 'Password check succeeds with re-hashed password with original hasher.');
} }
/**
* Tests password validation when the hash is NULL.
*
* @covers ::check
*/
public function testEmptyHash(): void {
$this->assertFalse($this->passwordHasher->check($this->password, NULL));
$this->assertFalse($this->passwordHasher->check($this->password, ''));
}
} }
...@@ -124,4 +124,14 @@ public function providerLongPasswords() { ...@@ -124,4 +124,14 @@ public function providerLongPasswords() {
return $passwords; return $passwords;
} }
/**
* Tests password check in case provided hash is NULL.
*
* @covers ::check
*/
public function testEmptyHash(): void {
$this->assertFalse($this->passwordHasher->check($this->password, NULL));
$this->assertFalse($this->passwordHasher->check($this->password, ''));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment