What potential pitfalls should be avoided when using password_hash and password_verify functions in PHP?
When using the `password_hash` and `password_verify` functions in PHP, it is important to avoid using a weak hashing algorithm or not salting the password before hashing it. This can lead to security vulnerabilities such as brute force attacks or rainbow table attacks. It is also crucial to securely store the hashed passwords to prevent data breaches.
$password = "secretPassword";
$options = [
'cost' => 12,
];
// Hash the password with bcrypt algorithm
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, $options);
// Verify the password
if (password_verify($password, $hashedPassword)) {
echo "Password is correct";
} else {
echo "Password is incorrect";
}