What alternative PHP functions or methods can be used for secure password hashing?
When storing passwords in a database, it is essential to hash them securely to protect user data in case of a breach. Instead of using the outdated `md5` or `sha1` functions, it is recommended to use stronger hashing algorithms like `password_hash` and `password_verify` functions provided by PHP. These functions use bcrypt algorithm by default and handle salting and hashing in a secure manner.
// Hashing a password
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Verifying a password
$enteredPassword = "secretPassword";
if (password_verify($enteredPassword, $hashedPassword)) {
echo "Password is correct!";
} else {
echo "Password is incorrect!";
}
Related Questions
- Are there any recommended tools or libraries that can assist in automatically extracting video metadata like width, height, duration, and bitrate in PHP?
- What are the risks of using constants as array indexes in PHP code for table generation?
- What is the significance of using base64 encoding and decoding as a workaround for serialization issues in PHP?