Module std::crypto::password

Password hashing and verification (Argon2id).

Hash passwords for storage and verify them later. Uses Argon2id with secure default parameters.

Examples

import std.crypto.password;

fn main() {
    let hash = password.hash("my_secret");
    match password.verify("my_secret", hash) {
        .Ok(true) => println("password matches"),
        .Ok(false) => println("password does not match"),
        .Err(error) => println(f"verification failed: {error}"),
    }
}

Contents

Functions

Function hash

pub fn hash(password: string) -> string

Hash a password using Argon2id with default parameters.

Returns the PHC-format hash string, suitable for storage.

Examples

import std.crypto.password;

fn main() {
    let hash = password.hash("hunter2");
}

Function verify

pub fn verify(password: string, hash: string) -> Result<bool, string>

Verify a password while distinguishing malformed hashes from mismatches.

Function hash_custom

pub fn hash_custom(password: string, cost: i64) -> Result<string, string>

Hash with a custom cost while rejecting values that cannot cross the ABI.