mirror of
https://git.sr.ht/~iwakuralain/text0Nly
synced 2025-07-27 15:36:11 +00:00
oh no
This commit is contained in:
parent
6727eea302
commit
18cf72acff
@ -9,21 +9,17 @@ header('Content-Security-Policy: default-src \'self\'; style-src \'self\' \'unsa
|
|||||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$debug = [];
|
|
||||||
try {
|
try {
|
||||||
$config = require 'config.php';
|
$config = require 'config.php';
|
||||||
$debug[] = "Config loaded";
|
|
||||||
|
|
||||||
$db = new PDO(
|
$db = new PDO(
|
||||||
"mysql:host={$config['db']['host']};dbname={$config['db']['name']}",
|
"mysql:host={$config['db']['host']};dbname={$config['db']['name']}",
|
||||||
$config['db']['user'],
|
$config['db']['user'],
|
||||||
$config['db']['pass']
|
$config['db']['pass']
|
||||||
);
|
);
|
||||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$debug[] = "Database connected";
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$debug[] = "Database error: " . $e->getMessage();
|
error_log("Database connection error: " . $e->getMessage());
|
||||||
die("Database connection error: " . $e->getMessage());
|
die("Database connection error");
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = '';
|
$error = '';
|
||||||
@ -32,46 +28,36 @@ $success = '';
|
|||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
|
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
|
||||||
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
|
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
$debug[] = "Login attempt for: " . $username;
|
|
||||||
|
|
||||||
if ($username && $password) {
|
if ($username && $password) {
|
||||||
try {
|
try {
|
||||||
$stmt = $db->prepare('SELECT id, password, is_blocked, login_attempts, last_attempt FROM users WHERE username = ?');
|
$stmt = $db->prepare('SELECT id, password, is_blocked, login_attempts, last_attempt FROM users WHERE username = ?');
|
||||||
$stmt->execute([$username]);
|
$stmt->execute([$username]);
|
||||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$debug[] = "User found: " . ($user ? 'yes' : 'no');
|
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
if ($user['is_blocked']) {
|
if ($user['is_blocked']) {
|
||||||
$error = 'Account is blocked';
|
$error = 'Account is blocked';
|
||||||
$debug[] = "Account blocked";
|
|
||||||
} else if ($user['login_attempts'] >= 5 && strtotime($user['last_attempt']) > strtotime('-15 minutes')) {
|
} else if ($user['login_attempts'] >= 5 && strtotime($user['last_attempt']) > strtotime('-15 minutes')) {
|
||||||
$error = 'Too many login attempts';
|
$error = 'Too many login attempts';
|
||||||
$debug[] = "Too many attempts";
|
|
||||||
} else if (password_verify($password, $user['password'])) {
|
} else if (password_verify($password, $user['password'])) {
|
||||||
$stmt = $db->prepare('UPDATE users SET login_attempts = 0, last_attempt = NOW() WHERE id = ?');
|
$stmt = $db->prepare('UPDATE users SET login_attempts = 0, last_attempt = NOW() WHERE id = ?');
|
||||||
$stmt->execute([$user['id']]);
|
$stmt->execute([$user['id']]);
|
||||||
$_SESSION['user_id'] = $user['id'];
|
$_SESSION['user_id'] = $user['id'];
|
||||||
$_SESSION['username'] = $username;
|
$_SESSION['username'] = $username;
|
||||||
$debug[] = "Login successful";
|
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
$stmt = $db->prepare('UPDATE users SET login_attempts = login_attempts + 1, last_attempt = NOW() WHERE id = ?');
|
$stmt = $db->prepare('UPDATE users SET login_attempts = login_attempts + 1, last_attempt = NOW() WHERE id = ?');
|
||||||
$stmt->execute([$user['id']]);
|
$stmt->execute([$user['id']]);
|
||||||
$error = 'Invalid password';
|
$error = 'Invalid password';
|
||||||
$debug[] = "Invalid password";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$error = 'User not found';
|
$error = 'User not found';
|
||||||
$debug[] = "User not found";
|
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
|
error_log("Login error: " . $e->getMessage());
|
||||||
$error = 'Server error';
|
$error = 'Server error';
|
||||||
$debug[] = "SQL Error: " . $e->getMessage();
|
|
||||||
$debug[] = "SQL State: " . $e->getCode();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +74,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
button { width: 100%; padding: 10px; background: #2196F3; color: white; border: none; cursor: pointer; }
|
button { width: 100%; padding: 10px; background: #2196F3; color: white; border: none; cursor: pointer; }
|
||||||
.error { color: red; }
|
.error { color: red; }
|
||||||
.success { color: green; }
|
.success { color: green; }
|
||||||
.debug { background: #f5f5f5; padding: 10px; margin: 10px 0; font-family: monospace; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -110,15 +95,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
<p><a href="register.php">Register</a> | <a href="index.php">Back to chat</a></p>
|
<p><a href="register.php">Register</a> | <a href="index.php">Back to chat</a></p>
|
||||||
|
|
||||||
<?php if (!empty($debug)): ?>
|
|
||||||
<div class="debug">
|
|
||||||
<strong>Debug info:</strong><br>
|
|
||||||
<?php foreach ($debug as $line): ?>
|
|
||||||
<?= htmlspecialchars($line) ?><br>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php ob_end_flush(); ?>
|
<?php ob_end_flush(); ?>
|
Loading…
x
Reference in New Issue
Block a user