What are the best practices for encrypting passwords in PHP scripts?

To securely store passwords in PHP scripts, it is best practice to use a strong hashing algorithm like bcrypt to encrypt the passwords. This ensures that even if the database is compromised, the passwords cannot be easily decrypted. Additionally, it is recommended to use a unique salt for each password to further enhance security.

// Generate a random salt
$salt = openssl_random_pseudo_bytes(16);

// Hash the password with bcrypt using the salt
$hashed_password = password_hash($password, PASSWORD_BCRYPT, ['salt' => $salt]);