What are some common pitfalls in PHP login systems, as seen in the provided code snippet?

One common pitfall in PHP login systems is storing passwords in plain text or using weak hashing algorithms. To improve security, passwords should be securely hashed using functions like password_hash() and password_verify(). Additionally, failing to properly sanitize input data can lead to SQL injection attacks. It's important to use prepared statements when interacting with the database to prevent this vulnerability.

// Example of securely hashing a password before storing it in the database
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

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