Home > Dev > PHP Security > Password Hashing

Password Hashing

This code securely hashes passwords using the password_hash and password_verify functions.

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

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

// Usage example
$hashed_password = hash_password('user_password');
$is_valid = verify_password('user_password', $hashed_password);
Back