What are some common security vulnerabilities in PHP login systems and how can they be mitigated?

One common security vulnerability in PHP login systems is SQL injection, where attackers can manipulate SQL queries to gain unauthorized access to the database. This can be mitigated by using prepared statements with parameterized queries to prevent user input from being interpreted as SQL commands.

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