What are the best practices for securely storing passwords in a PHP application, especially in the context of user logins?

Storing passwords securely in a PHP application is crucial to protect user data. The best practice is to hash passwords using a strong hashing algorithm like bcrypt and store the hashed passwords in the database. This ensures that even if the database is compromised, the passwords remain secure.

// Hashing a password using bcrypt
$password = "user_password";
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Storing the hashed password in the database
// Example SQL query: INSERT INTO users (username, password) VALUES ('user123', '$hashed_password');