Skip to content

Commit a495d6b

Browse files
Improve readability of authenticatePasswordVerifyHash()
1 parent 2333422 commit a495d6b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Auth/Source/SQL2.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ protected function authenticatePasswordVerifyHash(
434434
throw new Error\Error('WRONGUSERPASS');
435435
}
436436

437-
$validPasswordHashFound = false;
438437
$passwordHash = null;
439438
foreach ($data as $row) {
440439
if ((!array_key_exists($hashColumn, $row)) || is_null($row[$hashColumn])) {
@@ -445,27 +444,27 @@ protected function authenticatePasswordVerifyHash(
445444
));
446445
throw new Error\Error('WRONGUSERPASS');
447446
}
448-
if (($passwordHash === null) && (strlen($row[$hashColumn]) > 0)) {
449-
$passwordHash = $row[$hashColumn];
450-
$validPasswordHashFound = true;
451-
} elseif ($passwordHash != $row[$hashColumn]) {
447+
448+
if (strlen($row[$hashColumn]) === 0) {
452449
Logger::error(sprintf(
453-
'sqlauth:%s: column %s must be THE SAME in every result tuple.',
450+
'sqlauth:%s: column `%s` must contain a valid password hash.',
454451
$this->authId,
455452
$hashColumn,
456453
));
457454
throw new Error\Error('WRONGUSERPASS');
458-
} elseif (strlen($row[$hashColumn]) === 0) {
455+
} elseif ($passwordHash === null) {
456+
$passwordHash = $row[$hashColumn];
457+
} elseif ($passwordHash != $row[$hashColumn]) {
459458
Logger::error(sprintf(
460-
'sqlauth:%s: column `%s` must contain a valid password hash.',
459+
'sqlauth:%s: column %s must be THE SAME in every result tuple.',
461460
$this->authId,
462461
$hashColumn,
463462
));
464463
throw new Error\Error('WRONGUSERPASS');
465464
}
466465
}
467466

468-
if ((!$validPasswordHashFound) || (!password_verify($password, $passwordHash))) {
467+
if (($passwordHash == null) || (!password_verify($password, $passwordHash))) {
469468
Logger::error('sqlauth:' . $this->authId . ': Auth query ' . $queryname .
470469
' password verification failed');
471470
/* Authentication with verify_password() failed, however that only means that

0 commit comments

Comments
 (0)