What are common pitfalls when using PHP for database login systems?

Common pitfalls when using PHP for database login systems include not properly sanitizing user input to prevent SQL injection attacks, storing passwords in plain text rather than hashing them for security, and not using prepared statements to prevent SQL injection attacks. To prevent these pitfalls, always sanitize user input using prepared statements, hash passwords before storing them in the database, and use prepared statements for all database queries.

// Sanitize user input using prepared statements
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = ? AND password = ?');
$stmt->execute([$username, $password]);

// Hash passwords before storing them in the database
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Use prepared statements for all database queries
$stmt = $pdo->prepare('INSERT INTO users (username, password) VALUES (?, ?)');
$stmt->execute([$username, $hashedPassword]);