What improvements could be made to the script to enhance its functionality and security?

Issue: The script currently lacks input validation and sanitization, making it vulnerable to SQL injection attacks. To enhance its functionality and security, we should implement proper input validation and sanitization techniques.

// Improving security by implementing input validation and sanitization
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';

// Validate and sanitize input
$username = filter_var($username, FILTER_SANITIZE_STRING);
$password = filter_var($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 code for authentication and authorization