BOT対策

This commit is contained in:
2025-12-12 19:40:02 +09:00
parent 6d6fa82fcf
commit 47cf4f9f54
4 changed files with 84 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ class User {
$doLogin = $_SERVER['REQUEST_METHOD'] === 'POST';
$error = '';
$nyuU = '';
if ($doLogin) {
if (!\verify_csrf_token($_POST['csrf_token'])) {
@@ -29,13 +30,21 @@ class User {
unset($_POST['csrf_token']);
$a = [];
if (count($_POST) === 2) {
$isBot = false;
if (count($_POST) === 4) {
$i = 0;
foreach ($_POST as $p) {
$a[(int)$i] = $p;
if ($i >= 2 && $p != '') $isBot = true;
$i++;
}
}
if ($isBot) {
header('Location: /');
exit();
}
$auth = new Auth($a[0]);
$res = $auth->isUserExist($a[0]);
if (!$res->isSuccess) {
@@ -43,6 +52,7 @@ class User {
} else {
$result = $auth->setToken($a[0], $a[1]);
if (!$result->isSuccess) {
$nyuU = $a[0];
$error = $result->message;
} else {
header('Location: /');
@@ -60,6 +70,7 @@ class User {
$tmpl->assign('menu', $this->getMenu());
$tmpl->assign('description', $description);
$tmpl->assign('error', $error);
$tmpl->assign('nyuU', $nyuU);
$tmpl->render('login');
} catch (\Exception $e) {
@@ -108,14 +119,21 @@ class User {
unset($_POST['csrf_token']);
$a = [];
if (count($_POST) === 4) {
$isBot = false;
if (count($_POST) === 8) {
$i = 0;
foreach ($_POST as $p) {
$a[(int)$i] = $p;
if ($i >= 4 && $p != '') $isBot = true;
$i++;
}
}
if ($isBot) {
header('Location: /');
exit();
}
$auth = new Auth;
$res = $auth->mkUser($a[0], $a[1], $a[2], $a[3]);
if (!$res->isSuccess) {