From 5ed67947e501c5b4f5c5bfd01808a802cedf02d6 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Mon, 16 Jun 2025 02:10:18 +0300 Subject: [PATCH] fixingfixin --- main/login.php | 91 ++++++++++++++++++++++++++++------------------- main/register.php | 6 ++-- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/main/login.php b/main/login.php index bb95d8b..ac05bfb 100644 --- a/main/login.php +++ b/main/login.php @@ -1,5 +1,5 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $error = ''; +$success = ''; + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING); $password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_STRING); - + if ($username && $password) { - $stmt = $db->prepare('SELECT id, password, is_moderator, login_attempts, last_attempt FROM users WHERE username = ?'); - $stmt->execute([$username]); - $user = $stmt->fetch(PDO::FETCH_ASSOC); - - if ($user) { - if ($user['login_attempts'] >= 5 && strtotime($user['last_attempt']) > strtotime('-15 minutes')) { - $error = 'Too many login attempts. Please try again later.'; - } else if (password_verify($password, $user['password'])) { - session_regenerate_id(true); - $_SESSION['user_id'] = $user['id']; - $_SESSION['username'] = $username; - $_SESSION['is_moderator'] = $user['is_moderator']; - - $stmt = $db->prepare('UPDATE users SET login_attempts = 0, last_attempt = NOW() WHERE id = ?'); - $stmt->execute([$user['id']]); - - header('Location: index.php'); - exit; + 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); + + if ($user) { + if ($user['is_blocked']) { + $error = 'Account is blocked'; + } else if ($user['login_attempts'] >= 5 && strtotime($user['last_attempt']) > strtotime('-15 minutes')) { + $error = 'Too many login 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; + 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'; + } } else { - $stmt = $db->prepare('UPDATE users SET login_attempts = login_attempts + 1, last_attempt = NOW() WHERE id = ?'); - $stmt->execute([$user['id']]); - $error = 'Invalid username or password'; + $error = 'User not found'; } - } else { - $error = 'Invalid username or password'; + } catch (PDOException $e) { + $error = 'Server error'; } } } @@ -55,21 +60,35 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - Login - + Text0Nly - Login + -
-

Login

+

Login

-
+
-
- - + +
+ + + +
+ +
+
+ +
-
Register | Back to chat
-
+

Register | Back to chat

- \ No newline at end of file + + \ No newline at end of file diff --git a/main/register.php b/main/register.php index a533b51..a8e79d2 100644 --- a/main/register.php +++ b/main/register.php @@ -1,5 +1,5 @@

Back to chat

- \ No newline at end of file + + \ No newline at end of file