How can the use of a "salt" enhance the security of password hashing in PHP?
Using a "salt" can enhance the security of password hashing in PHP by adding random data to each password before hashing, making it more difficult for attackers to use precomputed hash tables (rainbow tables) to crack passwords. This adds an extra layer of security by ensuring that even passwords that are the same will have different hashes due to the unique salt added to each one.
// Generate a random salt
$salt = bin2hex(random_bytes(16));
// Combine the password and salt before hashing
$hashed_password = hash('sha256', $password . $salt);
// Store the hashed password and salt in the database
// When verifying the password, retrieve the salt for the user and repeat the hashing process