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) {