Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Cloudflare Captcha
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / Tutorials

2025-02-25 06:01:33
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
// CLOUDFLARE TURNSTILE RECAPTCHA
$site_config['CLOUDSITEKEY'] = 'add-key-here'; // Cloudflare turnstile captcha Sitekey
$site_config['CLOUDSECRET'] = 'add-key-here'; // Cloudflare turnstile captcha Secretkey


here 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)
Last edited by MicroMonkey on 2025-02-25 06:02:39
2025-02-25 13:37:55
Thanks mate, an really easy way to implement code on login and other pages...


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2025-02-28 21:40:05
Big thanks MicroMonkey ☺

I'll test this as soon as I have time, thank you very much!


2025-04-06 17:11:58
Big thanks MicroMonkey, it works #1 for me  👍  👌
Cloudflare.png
Cloudflare.png

Last edited by spiritblue on 2025-04-06 17:12:52
2025-05-26 19:46:35
Where to get the keys
2025-05-26 23:00:00
https://www.cloudflare.com/

https://www.cloudflare.com/application-services/products/turnstile/
Last edited by coco on 2025-05-26 23:00:47
2025-12-01 11:44:39
No working. No login
2026-01-16 04:43:17
which one better google captcha or cloudflare captcha?
2026-01-16 04:44:12
don't forget put the key
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728