What are the advantages of using password_hash() function in PHP for storing user passwords securely?

Storing user passwords securely is crucial to protect user data from unauthorized access. One way to achieve this is by using the password_hash() function in PHP, which securely hashes passwords using a strong hashing algorithm. This function automatically generates a unique salt for each password, making it resistant to various types of attacks such as brute force and rainbow table attacks.

// Hashing the user's password
$password = "password123";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Storing the hashed password in the database
// Example: $sql = "INSERT INTO users (username, password) VALUES ('$username', '$hashed_password')";