mirror of
https://git.sr.ht/~iwakuralain/text0Nly
synced 2025-07-27 15:36:11 +00:00
89 lines
3.4 KiB
PHP
89 lines
3.4 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
require_once 'functions.php';
|
|
|
|
session_start();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
try {
|
|
$pdo = new PDO(
|
|
"mysql:host={$config['db_host']};dbname={$config['db_name']};charset=utf8mb4",
|
|
$config['db_user'],
|
|
$config['db_pass'],
|
|
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
|
|
);
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && password_verify($password, $user['password'])) {
|
|
if ($user['is_blocked']) {
|
|
$error = "Аккаунт заблокирован: " . htmlspecialchars($user['block_reason']);
|
|
} else {
|
|
$_SESSION['user_id'] = $user['id'];
|
|
$_SESSION['username'] = $user['username'];
|
|
$_SESSION['is_moderator'] = $user['is_moderator'];
|
|
|
|
$stmt = $pdo->prepare("UPDATE users SET login_attempts = 0, last_attempt = NULL WHERE id = ?");
|
|
$stmt->execute([$user['id']]);
|
|
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
} else {
|
|
if ($user) {
|
|
$stmt = $pdo->prepare("UPDATE users SET login_attempts = login_attempts + 1, last_attempt = CURRENT_TIMESTAMP WHERE id = ?");
|
|
$stmt->execute([$user['id']]);
|
|
|
|
if ($user['login_attempts'] >= 4) {
|
|
$stmt = $pdo->prepare("UPDATE users SET is_blocked = 1, block_reason = 'Превышено количество попыток входа' WHERE id = ?");
|
|
$stmt->execute([$user['id']]);
|
|
$error = "Аккаунт заблокирован из-за превышения количества попыток входа";
|
|
} else {
|
|
$error = "Неверный пароль";
|
|
}
|
|
} else {
|
|
$error = "Пользователь не найден";
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error = "Ошибка сервера";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Вход</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Вход</h1>
|
|
<?php if (isset($error)): ?>
|
|
<div class="error"><?php echo $error; ?></div>
|
|
<?php endif; ?>
|
|
<?php if (isset($success)): ?>
|
|
<div class="success"><?php echo $success; ?></div>
|
|
<?php endif; ?>
|
|
<form method="POST" action="">
|
|
<div class="form-group">
|
|
<label for="username">Имя пользователя:</label>
|
|
<input type="text" id="username" name="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Пароль:</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit">Войти</button>
|
|
</form>
|
|
<p>Нет аккаунта? <a href="register.php">Зарегистрироваться</a></p>
|
|
</div>
|
|
</body>
|
|
</html>
|