How can one securely store passwords in the .pwd file for htaccess authentication in PHP?

To securely store passwords in the .pwd file for htaccess authentication in PHP, you can use a hashing algorithm like bcrypt to encrypt the passwords before storing them in the file. This ensures that the passwords are not stored in plain text and are more secure.

$password = 'password123';
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);
file_put_contents('.pwd', $hashedPassword);