How can password_hash() and password_verify() be used to store and verify passwords securely in PHP?

Storing passwords securely is crucial to protect user data. PHP provides the password_hash() function to securely hash passwords and the password_verify() function to verify hashed passwords. By using these functions, passwords are stored in a hashed format, making it difficult for attackers to reverse engineer the original password.

// Storing password securely using password_hash()
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Verifying password using password_verify()
$userInput = "secretPassword";
if (password_verify($userInput, $hashedPassword)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}