Hash the password for an unknown username at login.

An unknown username got a fast answer, which showed which usernames exist.
This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent c8030b759d
commit 061f9c1a37
3 changed files with 42 additions and 4 deletions
+15
View File
@@ -211,6 +211,21 @@ function password_hash_is_stored($username, $hash) {
return $row && $row['password'] === $hash;
}
/*
* TRUE if $password matches $stored_hash. For an unknown editor
* ($stored_hash is NULL), it hashes the password anyway, so that the
* answer takes as long as for a wrong password, and does not show which
* usernames exist.
*/
function editor_password_valid($password, $stored_hash) {
if ($stored_hash === NULL) {
password_hash($password, password_algorithm());
return FALSE;
}
// password_verify() also accepts hashes made by the old crypt() call
return password_verify($password, $stored_hash);
}
/*
* After a successful login, move an old hash (MD5-crypt, bcrypt) to the
* current algorithm. If the column is too short and MySQL cut the new