proofs
ModuleSecrets a user proves they know: passwords, one-time codes, tokens and
passphrases, each generated and stored through a Hash.
Contents
4 submodules, and what the module defines itself.
use utopia_auth::proofs::Proof;pub trait ProofA kind of secret: how it is generated, and the Hash that stores it.
Every proof hashes with Argon2 unless set otherwise.
proofs::code
Own pageNumeric one-time codes, such as those sent by email or SMS.
use utopia_auth::proofs::code::Code;pub struct CodeA numeric one-time code, 6 digits by default.
use utopia_auth::proofs::{Code, Proof};
let code = Code::new(8)?;
let secret = code.generate()?;
assert_eq!(secret.len(), 8);
assert!(secret.iter().all(u8::is_ascii_digit));Default.proofs::password
Own pageUser passwords: a registry of named hashes, the one in use, and random password generation.
use utopia_auth::proofs::password::Password;pub struct PasswordA user password: a registry of named hashes (every built-in by default), the one in use, and how generated passwords look (16 characters from a symbol-rich charset).
use utopia_auth::proofs::{Password, Proof};
let mut password = Password::new();
password.use_hash("bcrypt")?;
let hash = password.hash(b"secret")?;
assert!(hash.starts_with(b"$2y$"));
assert!(password.verify(b"secret", &hash)?);
// Generated passwords are 16 characters long.
assert_eq!(password.generate()?.len(), 16);Default.use utopia_auth::proofs::password::set_options;pub fn set_options(hash: &mut dyn Hash, options: &Array) -> Result<(), Error>Sets every option in options on hash, in order.
Fails with Error::Type at the first integer key: option names are strings.
pub const ARGON2: &str = "argon2"The registered name of Argon2.
pub const BCRYPT: &str = "bcrypt"The registered name of Bcrypt.
pub const MD5: &str = "md5"The registered name of Md5.
pub const PHPASS: &str = "phpass"The registered name of the phpass hash.
pub const SCRYPT: &str = "scrypt"The registered name of Scrypt.
pub const SCRYPT_MODIFIED: &str = "scryptMod"The registered name of ScryptModified.
pub const SHA: &str = "sha"The registered name of Sha.
proofs::phrase
Own pageTwo-word passphrases that are easy to read out and type.
use utopia_auth::proofs::phrase::Phrase;pub struct PhraseA two-word passphrase, "Adjective noun", such as Brave kangaroo.
use utopia_auth::proofs::{Phrase, Proof};
let phrase = Phrase::new().generate()?;
let words: Vec<&[u8]> = phrase.split(|b| *b == b' ').collect();
assert_eq!(words.len(), 2);
assert!(words[0][0].is_ascii_uppercase());Default.proofs::token
Own pageRandom hex tokens, such as those in magic links and recovery emails.
use utopia_auth::proofs::token::Token;pub struct TokenA random hex token, 256 characters by default.
use utopia_auth::proofs::{Proof, Token};
let token = Token::new(64)?;
let secret = token.generate()?;
assert_eq!(secret.len(), 64);
assert!(secret.iter().all(u8::is_ascii_hexdigit));Default.