Are there any security vulnerabilities in the way user inputs are handled in the PHP script?

The issue is that the PHP script is not sanitizing user inputs, making it vulnerable to attacks like SQL injection or cross-site scripting. To solve this, you should always sanitize and validate user inputs before using them in your script.

// Sanitize and validate user inputs
$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
$password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);

// Use prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username AND password = :password");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->execute();

// Rest of the script