Is using password_hash() function the recommended method for hashing passwords in PHP, or is using other methods like SHA512 still acceptable?

Using the password_hash() function is the recommended method for hashing passwords in PHP as it automatically generates a secure salt and uses a strong hashing algorithm. Using other methods like SHA512 directly is not recommended as they do not include the necessary salt or additional security features.

$password = "mySecurePassword";

// Hash the password using password_hash()
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Verify the hashed password
if (password_verify($password, $hashedPassword)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}