How can the use of salts enhance the security of password storage and verification in PHP?
Using salts in password storage and verification adds an extra layer of security by appending a random string of characters to each password before hashing it. This makes it more difficult for attackers to crack passwords using techniques like rainbow tables.
// Generate a random salt
$salt = bin2hex(random_bytes(16));
// Combine the password and salt, then hash
$hashed_password = hash('sha256', $password . $salt);
// Store the hashed password and salt in the database
// Verify the password by retrieving the salt for the user and hashing the input password with it