What are the best practices for generating and using salts in password hashing to ensure security and data integrity in PHP applications?

To ensure security and data integrity in PHP applications when hashing passwords, it is essential to use unique salts for each password. Salts are random values added to passwords before hashing to prevent the same password from resulting in the same hash. It is crucial to generate a strong and random salt for each password and store it securely along with the hashed password.

// Generate a random salt
$salt = bin2hex(random_bytes(16));

// Combine the password and salt
$hashed_password = hash('sha256', $password . $salt);

// Store the hashed password and salt in the database
// Make sure to securely store the salt along with the hashed password