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