How to prevent spam auto-registering account for XenForo 2

Tutoriel How to prevent spam auto-registering account for XenForo 2

Add-on xenforo 2

Ressources et modules complémentaires pour XenForo 2

Styles xenforo 2

Styles / Thèmes et apparence pour xenforo 2

Templates xenforo 2

Codes pour modifier les templates sur xenforo 2

Section Premium

Add-on et Styles pour membre Premium
How to prevent spam auto-registering account for XenForo 2

Tutoriel How to prevent spam auto-registering account for XenForo 2

Catégorie Catégorie Tutoriel
Titre du sujet Titre du sujet How to prevent spam auto-registering account for XenForo 2
Auteur de la discussion Auteur de la discussion laurent68
Date de début Date de début
Réponses Réponses 0
Affichages Affichages 151
Réaction Réaction 0
Dernier message par Dernier message par laurent68

laurent68

Fondateur

Staff
fondateur
Réputation: 100%
Discussions
4 855
Messages
12 608
Solutions
85
J'aime
7 890
Points
198
Hello everyone, today I will guide you on how to prevent spam auto-registering nick for XenForo 2

11.png


To accomplish this, please follow my instructions.:

Navigate to the "PAGE_CONTAINER" template and find
HTML:
<xf:if is="$xf.options.registrationSetup.enabled">
                                <a href="{{ link('register') }}" class="p-navgroup-link p-navgroup-link--textual p-navgroup-link--register"
                                    data-xf-click="overlay" data-follow-redirects="on">
                                    <span class="p-navgroup-linkText">{{ phrase('register') }}</span>
                                </a>
                            </xf:if>

Replace it with:
HTML:
<xf:if is="$xf.options.registrationSetup.enabled">
                                <a href="{{ link('register') }}" class="p-navgroup-link p-navgroup-link--textual p-navgroup-link--register"
        data-follow-redirects="on">
        <span class="p-navgroup-linkText">{{ phrase('register') }}</span>
    </a>
                            </xf:if>

Afterward, create a file named antispam.php next to index.php and paste the following code into it:
PHP:
<?php
session_start();

// Change to your actual password
$real_password = 'XenForo';

// Generate hashed password
$correct_password_hash = password_hash($real_password, PASSWORD_DEFAULT);

// Maximum number of login attempts before IP lockout
$max_login_attempts = 3;

// Lockout duration after reaching maximum login attempts (in seconds)
$lockout_duration = 300; // 5 minutes

// Check login status
if (!isset($_SESSION['loggedIn'])) {
    $_SESSION['loggedIn'] = false;
}

// Check if IP is locked
if (isset($_SESSION['failed_login_attempts']) && $_SESSION['failed_login_attempts'] >= $max_login_attempts && isset($_SESSION['lockout_time']) && $_SESSION['lockout_time'] > time() - $lockout_duration) {
    $time_remaining = $_SESSION['lockout_time'] - time();
    die("IP locked out. Please try again in $time_remaining seconds.");
}

// Check password when submitted
if (isset($_POST['password'])) {
    $password = $_POST['password'];
    if (password_verify($password, $correct_password_hash)) {
        $_SESSION['loggedIn'] = true;
        $_SESSION['failed_login_attempts'] = 0; // Reset failed login attempts when login succeeds
        header("Location: /register/index.php");
        exit();
    } else {
        // Increase failed login attempts
        $_SESSION['failed_login_attempts'] = isset($_SESSION['failed_login_attempts']) ? $_SESSION['failed_login_attempts'] + 1 : 1;
 
        // If maximum login attempts reached, lock IP
        if ($_SESSION['failed_login_attempts'] >= $max_login_attempts) {
            $_SESSION['lockout_time'] = time() + $lockout_duration;
            $error = "IP locked out. Please try again in $lockout_duration seconds.";
        } else {
            $error = 'Invalid password.';
        }
    }
}

if (!$_SESSION['loggedIn']): ?>
<html>
<head>
<title>Register User</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="Register users" />
<meta name="keywords" content="Register users" />
</head>
<body>
<div align="center">
<?php if (isset($error)) echo "<p>" . htmlspecialchars($error) . "</p>"; ?>
<p>Please enter XenForo below:</p>
<form method="post">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login">
</form>
<?php
if(isset($_SESSION['lockout_time']) && $_SESSION['lockout_time'] > time() - $lockout_duration) {
    $time_remaining = $_SESSION['lockout_time'] - time();
    echo "Time remaining: $time_remaining seconds";
}
?>
</div>
</body>
</html>
<?php
exit();
endif;
?>

Go to src/XF/Pub/Controller/Register.php

Find:


And replace it with:

The code will block the IP for 300 seconds if the wrong password is entered, ensuring XSS security.

That's it, you're all set! Wishing you success!
 
Contenu similaire Les plus vues Voir plus
Retour
Haut Bas