• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Hướng dẫn chống spam auto register nick cho XenForo 2 - How to prevent spam auto-registering account for XenForo 2

Admin

Well-Known Member
Staff member
Administrator
Chào các bạn, hôm nay tuoitreit.vn xin hướng dẫn các bạn cách chống spam tự động đăng ký nick cho xenforo 2

53775683637_f0c32cf8df_o.png


Để làm được bạn hãy làm theo hướng dẫn của tuoitreit.vn nhé

Đi đến "PAGE_CONTAINER" template và tìm

Code:
<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>

Thay thế bằng:
Code:
<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>

Sau đó tạo 1 file là antispam.php ngang hàng index.php và dán code sau vào
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;
?>

Vào src/XF/Pub/Controller/Register.php

Tìm
PHP:
namespace XF\Pub\Controller;
Và thay bằng
PHP:
namespace XF\Pub\Controller;
include 'antispam.php';

Code sẽ khóa IP 300 giây nếu nhập sai mật khẩu, bảo mật chống XSS..

Vậy là xong rồi đó, chúc bạn thành công!
Mọi sao chép vui lòng ghi rõ nguồn tuoitreit.vn
 

Facebook Comments

New posts New threads New resources

Back
Top