Struct dryoc::pwhash::PwHash

source ·
pub struct PwHash<Hash: Bytes, Salt: Bytes> { /* private fields */ }
Expand description

Password hash implementation based on Argon2, compatible with libsodium’s crypto_pwhash_* functions.

Implementations

Hashes password with a random salt and config, returning the hash, salt, and config upon success.

Hashes password with a random salt and a default configuration suitable for interactive hashing, returning the hash, salt, and config upon success.

Hashes password with a random salt and a default configuration suitable for moderate hashing, returning the hash, salt, and config upon success.

Hashes password with a random salt and a default configuration suitable for sensitive hashing, returning the hash, salt, and config upon success.

Available on crate feature base64 only.

Returns a string-encoded representation of this hash, salt, and config, suitable for storage in a database.

It’s recommended that you use the Serde support instead of this function, however this function is provided for compatiblity reasons.

The string returned is compatible with libsodium’s crypto_pwhash_str, crypto_pwhash_str_verify, and crypto_pwhash_str_needs_rehash functions, but only when the hash and salt length values match those supported by libsodium. This implementation supports variable-length salts and hashes, but libsodium’s does not.

Example
use dryoc::pwhash::*;

let password = b"Come what come may, time and the hour runs through the roughest day.";

let pwhash = PwHash::hash_with_defaults(password).expect("unable to hash");
let pw_string = pwhash.to_string();

let parsed_pwhash =
    PwHash::from_string_with_defaults(&pw_string).expect("couldn't parse hashed password");

parsed_pwhash.verify(password).expect("verification failed");
parsed_pwhash
    .verify(b"invalid password")
    .expect_err("verification should have failed");

Verifies that this hash, salt, and config is valid for password.

Hashes password with salt and config, returning the hash, salt, and config upon success.

Available on crate feature base64 only.

Creates a new password hash instance by parsing hashed_password. Compatible with libsodium’s crypto_pwhash_str* functions, and supports variable-length encoding for the hash and salt.

It’s recommended that you use the Serde support instead of this function, however this function is provided for compatiblity reasons.

Constructs a new instance from hash, salt, and config, consuming them.

Moves the hash, salt, and config out of this instance, returning them as a tuple.

Derives a keypair from password and salt, using config.

Hashes password using default (interactive) config parameters, returning the Vec-based hash and salt, with config, upon success.

This function provides reasonable defaults, and is provided for convenience.

Available on crate feature base64 only.

Parses the hashed_password string, returning a new hash instance upon success. Wraps PwHash::from_string, provided for convenience.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more
Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.