diff --git a/functions.php b/functions.php index 3fa706d7..6e12222c 100644 --- a/functions.php +++ b/functions.php @@ -2534,18 +2534,18 @@ function countRecentFailedAttempts($email, $minutesBack = 15) { } $email = strtolower(trim($email)); - $cutoffTime = date('Y-m-d H:i:s', time() - ($minutesBack * 60)); // Count failed attempts by email only (IP may vary due to proxies, mobile networks, etc) + // Using DATE_SUB to ensure proper datetime comparison $sql = "SELECT COUNT(*) as count FROM login_attempts WHERE email = ? AND success = 0 - AND attempted_at > ?"; + AND attempted_at > DATE_SUB(NOW(), INTERVAL ? MINUTE)"; $stmt = $conn->prepare($sql); if (!$stmt) { return 0; } - $stmt->bind_param('ss', $email, $cutoffTime); + $stmt->bind_param('si', $email, $minutesBack); $stmt->execute(); $stmt->bind_result($count); $stmt->fetch();