How can one ensure the security of password hashes when using mcrypt_create_iv() to generate salt values in PHP?
To ensure the security of password hashes when using mcrypt_create_iv() to generate salt values in PHP, it is recommended to use a secure random function like random_bytes() instead. This will generate cryptographically secure random bytes for use as salts, making it more difficult for attackers to crack the hashes.
// Generate a secure random salt using random_bytes()
$salt = random_bytes(16);
// Use the salt in password hashing
$password = 'password123';
$hashed_password = password_hash($password, PASSWORD_DEFAULT, ['salt' => $salt]);
// Verify the hashed password
if (password_verify($password, $hashed_password)) {
echo 'Password is correct!';
} else {
echo 'Password is incorrect!';
}