From 850958a45efe066652cfe55ace6bfdb1a2ff08ba Mon Sep 17 00:00:00 2001 From: Zankaria Date: Thu, 14 Nov 2024 15:27:11 +0100 Subject: [PATCH] functions.php: add optional password check for has_any_history --- inc/functions.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 83333af0..5d0d6933 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -922,9 +922,10 @@ function checkBan($board = false) { * Checks if the given IP has any previous posts. * * @param string $ip The IP to check. + * @param ?string $passwd If not null, check also by password. * @return bool True if the ip has already sent at least one post, false otherwise. */ -function has_any_history(string $ip): bool { +function has_any_history(string $ip, ?string $passwd): bool { global $config; if ($config['cache']['enabled']) { @@ -935,8 +936,14 @@ function has_any_history(string $ip): bool { } foreach (listBoards(true) as $board_uri) { - $query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri)); - $query->bindValue(':ip', $ip); + if ($passwd === null) { + $query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri)); + $query->bindValue(':ip', $ip); + } else { + $query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip OR `password` = :passwd LIMIT 1', $board_uri)); + $query->bindValue(':ip', $ip); + $query->bindValue(':passwd', $passwd); + } $query->execute() or error(db_error()); if ($query->fetchColumn() !== false) {