prepare( "SELECT id, username, password FROM users WHERE username = ? LIMIT 1" ); $stmt->execute([$username]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ( $user && password_verify( $password, $user['password'] ) ) { /* |-------------------------------------------------------------------------- | Session Fixation Protection |-------------------------------------------------------------------------- */ session_regenerate_id(true); $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; header("Location: dashboard.php"); exit; } else { sleep(1); // Basic brute-force delay $error = "Invalid username or password"; } } } ?>
= htmlspecialchars($error) ?>