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");
    if password.verify("my_secret", hash) {
        println("password matches");
    }
}

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

let hash = password.hash("hunter2");

Function verify

pub fn verify(password: String, hash: String) -> bool

Verify a password against a hash.

Returns true if the password matches, false otherwise.

Examples

if password.verify("hunter2", stored_hash) {
    println("access granted");
}

Function hash_custom

pub fn hash_custom(password: String, cost: i32) -> String

Hash a password using Argon2id with a custom cost (iteration count).

Higher cost values are slower but more secure. The default is 3.

Examples

let hash = password.hash_custom("hunter2", 6);