What are common pitfalls to avoid when creating a login system in PHP, especially in terms of SQL injection vulnerabilities?

One common pitfall to avoid when creating a login system in PHP is SQL injection vulnerabilities. To prevent this, you should always use prepared statements with parameterized queries to securely interact with the database.

// Using 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();
$user = $stmt->fetch();