What are some common methods for encrypting passwords in PHP applications?

Storing passwords in plain text in a database is a major security risk. To address this, passwords should be encrypted before being stored. One common method for encrypting passwords in PHP applications is to use the password_hash() function with the PASSWORD_DEFAULT algorithm, which securely hashes passwords using bcrypt.

// Encrypting a password before storing it in the database
$password = 'secret_password';
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Storing the hashed password in the database
// INSERT INTO users (username, password) VALUES ('john_doe', '$hashed_password');