Rust

proofs

Module

Secrets 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;
Rust
pub trait Proof

A kind of secret: how it is generated, and the Hash that stores it.

Every proof hashes with Argon2 unless set otherwise.

proofs::code

Own page

Numeric one-time codes, such as those sent by email or SMS.

use utopia_auth::proofs::code::Code;
Rust
pub struct Code

A numeric one-time code, 6 digits by default.

Rust
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));
Also implements Default.

proofs::password

Own page

User passwords: a registry of named hashes, the one in use, and random password generation.

use utopia_auth::proofs::password::Password;
Rust
pub struct Password

A 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).

Rust
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);
Also implements Default.
use utopia_auth::proofs::password::set_options;
Rust
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.

Rust
pub const ARGON2: &str = "argon2"

The registered name of Argon2.

Rust
pub const BCRYPT: &str = "bcrypt"

The registered name of Bcrypt.

Rust
pub const MD5: &str = "md5"

The registered name of Md5.

Rust
pub const PHPASS: &str = "phpass"

The registered name of the phpass hash.

Rust
pub const SCRYPT: &str = "scrypt"

The registered name of Scrypt.

Rust
pub const SCRYPT_MODIFIED: &str = "scryptMod"

The registered name of ScryptModified.

Rust
pub const SHA: &str = "sha"

The registered name of Sha.

proofs::phrase

Own page

Two-word passphrases that are easy to read out and type.

use utopia_auth::proofs::phrase::Phrase;
Rust
pub struct Phrase

A two-word passphrase, "Adjective noun", such as Brave kangaroo.

Rust
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());
Also implements Default.

proofs::token

Own page

Random hex tokens, such as those in magic links and recovery emails.

use utopia_auth::proofs::token::Token;
Rust
pub struct Token

A random hex token, 256 characters by default.

Rust
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));
Also implements Default.