Home > Dev > Crypto > Password Hashing with Argon2

Password Hashing with Argon2

This code snippet demonstrates how to securely hash and verify passwords using Argon2.

function hash_password($password) {
    return password_hash($password, PASSWORD_ARGON2ID);
}

function verify_password($password, $hash) {
    return password_verify($password, $hash);
}

// Usage example
$password = 'user_password';
$hash = hash_password($password);
$is_valid = verify_password($password, $hash);

echo "Password Hash: " . $hash . "\n";
echo "Is Valid: " . ($is_valid ? 'Yes' : 'No') . "\n";
Back