Are there best practices for securely encrypting and storing passwords in PHP databases?

To securely encrypt and store passwords in PHP databases, it is recommended to use a strong hashing algorithm like bcrypt along with a unique salt for each password. This helps protect the passwords from being easily cracked in case of a data breach. Additionally, it is important to avoid storing plain text passwords in the database.

// Generate a unique salt for each password
$salt = uniqid(mt_rand(), true);

// Hash the password using bcrypt with the generated salt
$hashed_password = password_hash($password . $salt, PASSWORD_BCRYPT);

// Store the hashed password and salt in the database
// Make sure to properly escape and sanitize input before storing in the database