I always used google for years, and I learned about cloudflare. I like it better personally. Here is my login page. This is stock TTv3 account-login.php from github edited to use cloudflares captcha.
Go here and sign up for free https://www.cloudflare.com/application-services/products/turnstile/
Get your keys
Add to backend/config.php
here is the entire login page
Go here and sign up for free https://www.cloudflare.com/application-services/products/turnstile/
Get your keys
Add to backend/config.php
// CLOUDFLARE TURNSTILE RECAPTCHA
$site_config['CLOUDSITEKEY'] = 'add-key-here'; // Cloudflare turnstile captcha Sitekey
$site_config['CLOUDSECRET'] = 'add-key-here'; // Cloudflare turnstile captcha Secretkeyhere is the entire login page
<?php
// Updated login for sql security May 14 2023
require_once("backend/functions.php");
dbconn();
session_start();
if (!empty($_REQUEST["returnto"])) {
if (!isset($_GET["nowarn"])) {
$nowarn = T_("MEMBERS_ONLY");
}
}
if (isset($_POST["username"]) && isset($_POST["password"])) {
if (!empty($_POST["username"]) && !empty($_POST["password"])) {
$username = htmlspecialchars($_POST["username"]);
$password = htmlspecialchars($_POST["password"]);
$password_hash = passhash($password);
$stmt = $GLOBALS["DBconnector"]->prepare("SELECT id, password, secret, status, enabled FROM users WHERE username = ? LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
if ($stmt->error) {
die("Query failed: " . $stmt->error);
}
$res = $stmt->get_result();
$row = $res->fetch_assoc();
if ($row) {
if ($row["password"] !== $password_hash) {
$message = T_("LOGIN_INCORRECT");
} elseif ($row["status"] === "pending") {
$message = T_("ACCOUNT_PENDING");
} elseif ($row["enabled"] === "no") {
$message = T_("ACCOUNT_DISABLED");
} else {
if (isset($_POST['cf-turnstile-response'])) {
$turnstile_response = $_POST['cf-turnstile-response'];
if (empty($turnstile_response)) {
$message = "Please complete the verification";
} else {
$secretKey = $site_config['CLOUDSECRET'];
$ip = $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://challenges.cloudflare.com/turnstile/v0/siteverify');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'secret' => $secretKey,
'response' => $turnstile_response,
'remoteip' => $ip
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$message = "Verification error: " . curl_error($ch);
}
curl_close($ch);
$response = json_decode($response);
if ($response->success !== true) {
$message = "Verification failed. Please try again.";
}
}
} else {
$message = "Verification missing. Please try again.";
}
}
} else {
$message = T_("LOGIN_INCORRECT");
}
} else {
$message = T_("NO_EMPTY_FIELDS");
}
if (!isset($message) || !$message) {
logincookie($row["id"], $row["password"], $row["secret"]);
if (!empty($_POST["returnto"])) {
header("Refresh: 0; url=" . $_POST["returnto"]);
die();
} else {
header("Refresh: 0; url=index.php");
die();
}
} else {
show_error_msg(T_("ACCESS_DENIED"), $message, 1);
}
}
logoutcookie();
stdhead(T_("LOGIN"));
if (isset($nowarn)) {
show_error_msg(T_("ERROR"), $nowarn, 0);
}
begin_frame(T_("LOGIN"));
?>
<form method="post" action="account-login.php">
<table border="0" cellpadding="3" align="center">
<tr>
<td align="center">
<b><?php echo T_("USERNAME"); ?>:</b>
<input type="text" size="40" name="username" />
</td>
</tr>
<tr>
<td align="center">
<b><?php echo T_("PASSWORD"); ?>:</b>
<input type="password" size="40" name="password" />
</td>
</tr>
<tr>
<td align="center">
<div class="cf-turnstile" data-sitekey="<?php echo $site_config['CLOUDSITEKEY']; ?>"></div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="<?php echo T_("LOGIN"); ?>" />
<br />
<br />
<i><?php echo T_("COOKIES");?></i>
</td>
</tr>
</table>
<?php
if (!empty($_REQUEST["returnto"])) {
?>
<input type="hidden" name="returnto" value="<?php echo cleanstr($_REQUEST["returnto"]); ?>" />
<?php
}
?>
</form>
<p align="center">
<a href="account-signup.php"><?php echo T_("SIGNUP"); ?></a> |
<a href="account-recover.php"><?php echo T_("RECOVER_ACCOUNT"); ?></a>
</p>
<?php
end_frame();
stdfoot();
?>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2025-02-25 06:02:39
