functions.php: add optional password check for has_any_history

This commit is contained in:
Zankaria 2024-11-14 15:27:11 +01:00
parent 1f05efd2dd
commit 850958a45e

View file

@ -922,9 +922,10 @@ function checkBan($board = false) {
* Checks if the given IP has any previous posts. * Checks if the given IP has any previous posts.
* *
* @param string $ip The IP to check. * @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. * @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; global $config;
if ($config['cache']['enabled']) { if ($config['cache']['enabled']) {
@ -935,8 +936,14 @@ function has_any_history(string $ip): bool {
} }
foreach (listBoards(true) as $board_uri) { foreach (listBoards(true) as $board_uri) {
$query = prepare(sprintf('SELECT `id` FROM ``posts_%s`` WHERE `ip` = :ip LIMIT 1', $board_uri)); if ($passwd === null) {
$query->bindValue(':ip', $ip); $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()); $query->execute() or error(db_error());
if ($query->fetchColumn() !== false) { if ($query->fetchColumn() !== false) {