What are common pitfalls when implementing a login system in PHP?

One common pitfall when implementing a login system in PHP is not properly sanitizing user input, which can lead to SQL injection attacks. To prevent this, always use prepared statements when interacting with the database. Another pitfall is storing passwords in plain text, which can compromise user security. Instead, passwords should be hashed using a secure hashing algorithm like bcrypt.

// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);

// Example of hashing passwords using bcrypt
$password = password_hash($password, PASSWORD_BCRYPT);