What are the advantages of using password_hash() and password_verify() functions in PHP for storing and verifying passwords?

Storing passwords securely is crucial for protecting user data. Using the password_hash() function in PHP helps to securely hash passwords before storing them in a database, making it difficult for hackers to retrieve the original passwords. The password_verify() function allows for easy verification of passwords during login attempts, ensuring that the entered password matches the hashed password stored in the database.

// Storing a password securely
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Save $hashedPassword in the database

// Verifying a password during login
$enteredPassword = "secretPassword";
$storedHashedPassword = "hashedPasswordFromDatabase";

if (password_verify($enteredPassword, $storedHashedPassword)) {
    // Password is correct
    echo "Login successful";
} else {
    // Password is incorrect
    echo "Login failed";
}