hashes
ModuleThe built-in password hashing algorithms, each a Hash
with its own options.
Contents
9 submodules.
hashes::argon2
Own pageThe Argon2id password hash.
use utopia_auth::hashes::argon2::Argon2;pub struct Argon2The Argon2id password hash, in the standard $argon2id$ format.
Options: type, memory_cost (KiB), time_cost and threads.
use utopia_auth::Hash;
use utopia_auth::hashes::Argon2;
let mut argon2 = Argon2::new();
argon2.set_memory_cost(7168).set_time_cost(5).set_threads(1);
let hash = argon2.hash(b"secret")?;
assert!(hash.starts_with(b"$argon2id$v=19$m=7168,t=5,p=1$"));
assert!(argon2.verify(b"secret", &hash)?);Default.hashes::bcrypt
Own pageThe bcrypt password hash.
use utopia_auth::hashes::bcrypt::Bcrypt;pub struct BcryptThe bcrypt password hash, in the $2y$ format.
Options: type and cost.
Default.hashes::md5
Own pageThe unsalted MD5 digest, for imported legacy passwords.
use utopia_auth::hashes::md5::Md5;pub struct Md5The unsalted MD5 digest of a password, as lowercase hex.
Weak: use it only to verify passwords imported from another system.
Default.hashes::password
Own pageThe shared bcrypt, Argon2id and crypt calls behind the hashes: the options they read and the random salt they draw.
hashes::phpass
Own pageThe phpass password hash used by WordPress and phpBB.
use utopia_auth::hashes::phpass::PHPass;pub struct PHPassThe phpass password hash, as WordPress and phpBB use it: $2a$ bcrypt
hashes, or $P$ portable MD5 hashes when portable_hashes is set (or
bcrypt fails).
Options: type, iteration_count_log2, portable_hashes and random_state.
Default.hashes::plaintext
Own pageA hash that stores the password as is.
use utopia_auth::hashes::plaintext::Plaintext;pub struct PlaintextA hash that stores the password unchanged.
Default.hashes::scrypt
Own pageThe scrypt password hash.
use utopia_auth::hashes::scrypt::Scrypt;pub struct ScryptThe scrypt key derivation as a password hash, in lowercase hex.
Options: type, costCpu (N), costMemory (r), costParallel (p),
length (bytes) and salt (used as given, a random hex string by default).
Default.hashes::scrypt_modified
Own pageFirebase's modified scrypt password hash.
use utopia_auth::hashes::scrypt_modified::ScryptModified;pub struct ScryptModifiedFirebase's modified scrypt: the signer key encrypted with AES-256-CTR under a key scrypt derives from the password, as base64.
Use it to verify passwords exported from Firebase Authentication.
Options: type, salt, saltSeparator, signerKey (all base64).
Default.hashes::sha
Own pageUnsalted SHA-1, SHA-2 and SHA-3 digests, for imported legacy passwords.
use utopia_auth::hashes::sha::Sha;pub struct ShaThe unsalted SHA digest of a password, as lowercase hex.
Its options hold only version (no type): the name of the algorithm.
Weak: use it only to verify passwords imported from another system.
use utopia_auth::Hash;
use utopia_auth::hashes::{Sha, ShaVersion};
let mut sha = Sha::new();
sha.set_version(ShaVersion::Sha256);
let hash = sha.hash(b"password")?;
assert_eq!(hash, b"5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8");Default.use utopia_auth::hashes::sha::ShaVersion;pub enum ShaVersionA SHA algorithm a Sha hash can use.