PasswordHash

Struct PasswordHash 

Source
pub struct PasswordHash(/* private fields */);
Available on crate feature password-hash only.
Expand description

Password hash encoded in the Modular Crypt Format (MCF). Owned form with builder functionality.

Password hashes in this format take the form ${id}$..., where {id} is a short numeric or alphanumeric algorithm identifier optionally containing a -, followed by $ as a delimiter, further followed by an algorithm-specific serialization of a password hash, typically using a variant (often an algorithm-specific variant) of Base64. This algorithm-specific serialization contains one or more fields ${first}[${second}]..., where each field only uses characters in the regexp range [A-Za-z0-9./+=,\-].

Example (SHA-crypt w\ SHA-512):

$6$rounds=100000$exn6tVc2j/MZD8uG$BI1Xh8qQSK9J4m14uwy7abn.ctj/TIAzlaVCto0MQrOFIeTXsc1iwzH16XEWo/a7c7Y9eVJvufVzYAs4EsPOy0

Implementations§

Source§

impl PasswordHash

Source

pub fn new(s: impl Into<String>) -> Result<PasswordHash, Error>

Parse the given input string, returning an PasswordHash if valid.

Source

pub fn as_password_hash_ref(&self) -> &PasswordHashRef

Borrow the contents of this password hash as a PasswordHashRef.

Similar conversions can be performed using AsRef, Borrow, and Deref, however this one is useful when the return type may be ambiguous and avoiding potential inference bugs is preferable.

Source

pub fn from_id(id: &str) -> Result<PasswordHash, Error>

Create an PasswordHash from an identifier.

§Returns

Error if the identifier is invalid.

Allowed characters match the regex: [a-z0-9\-], where the first and last characters do NOT contain a -.

Source

pub fn push_base64(&mut self, field: &[u8], base64_encoding: Base64)

Available on crate feature base64 only.

Encode the given data as the specified variant of Base64 and push it onto the password hash string, first adding a $ delimiter.

Source

pub fn push_displayable<D>(&mut self, displayable: D) -> Result<(), Error>
where D: Display,

Push a type which impls fmt::Display, first adding a $ delimiter and ensuring the added characters comprise a valid field.

Source

pub fn push_field(&mut self, field: Field<'_>)

Push an additional field onto the password hash string, first adding a $ delimiter.

Source

pub fn push_str(&mut self, s: &str) -> Result<(), Error>

Push a raw string onto the MCF hash, first adding a $ delimiter and also ensuring it validates as a Field.

§Errors
  • If the provided str fails to validate as a Field (i.e. contains characters outside the allowed set)

Methods from Deref<Target = PasswordHashRef>§

Source

pub fn as_str(&self) -> &str

Get the contained string as a str.

Source

pub fn id(&self) -> &str

Get the algorithm identifier for this MCF hash.

Source

pub fn fields(&self) -> Fields<'_>

Get an iterator over the parts of the password hash as delimited by $, excluding the initial identifier.

Trait Implementations§

Source§

impl AsRef<PasswordHashRef> for PasswordHash

Source§

fn as_ref(&self) -> &PasswordHashRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for PasswordHash

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<PasswordHashRef> for PasswordHash

Source§

fn borrow(&self) -> &PasswordHashRef

Immutably borrows from an owned value. Read more
Source§

impl Clone for PasswordHash

Source§

fn clone(&self) -> PasswordHash

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CustomizedPasswordHasher<PasswordHash> for Yescrypt

Source§

type Params = Params

Algorithm-specific parameters.
Source§

fn hash_password_customized( &self, password: &[u8], salt: &[u8], alg_id: Option<&str>, version: Option<Version>, params: Params, ) -> Result<PasswordHash>

Compute a [PasswordHash] from the provided password using an explicit set of customized algorithm parameters as opposed to the defaults. Read more
Source§

fn hash_password_with_params( &self, password: &[u8], salt: &[u8], params: Self::Params, ) -> Result<H, Error>

Compute a [PasswordHash] using customized parameters only, using the default algorithm and version.
Source§

impl Debug for PasswordHash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for PasswordHash

Source§

type Target = PasswordHashRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &PasswordHashRef

Dereferences the value.
Source§

impl Display for PasswordHash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a PasswordHash> for &'a PasswordHashRef

Source§

fn from(hash: &'a PasswordHash) -> &'a PasswordHashRef

Converts to this type from the input type.
Source§

impl From<&PasswordHashRef> for PasswordHash

Source§

fn from(hash: &PasswordHashRef) -> PasswordHash

Converts to this type from the input type.
Source§

impl FromStr for PasswordHash

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<PasswordHash, Error>

Parses a string s to return a value of this type. Read more
Source§

impl Ord for PasswordHash

Source§

fn cmp(&self, other: &PasswordHash) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for PasswordHash

Source§

fn eq(&self, other: &PasswordHash) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PasswordHash

Source§

fn partial_cmp(&self, other: &PasswordHash) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PasswordHasher<PasswordHash> for Yescrypt

Source§

fn hash_password_with_salt( &self, password: &[u8], salt: &[u8], ) -> Result<PasswordHash>

Compute the hash H from the given password and salt, potentially using configuration stored in &self for the parameters, or otherwise the recommended defaults. Read more
Source§

fn hash_password(&self, password: &[u8]) -> Result<H, Error>

Available on crate feature getrandom only.
Compute the hash H from the given password, potentially using configuration stored in &self for the parameters, or otherwise the recommended defaults. Read more
Source§

fn hash_password_with_rng<R>( &self, rng: &mut R, password: &[u8], ) -> Result<H, Error>
where R: TryCryptoRng + ?Sized,

Available on crate feature rand_core only.
Compute the hash H from the given password, potentially using configuration stored in &self for the parameters, or otherwise the recommended defaults. Read more
Source§

impl PasswordVerifier<PasswordHash> for Yescrypt

Source§

fn verify_password(&self, password: &[u8], hash: &PasswordHash) -> Result<()>

Compute this password hashing function against the provided password using the parameters from the provided password hash and see if the computed output matches.
Source§

impl TryFrom<&str> for PasswordHash

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<PasswordHash, Error>

Performs the conversion.
Source§

impl TryFrom<String> for PasswordHash

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: String) -> Result<PasswordHash, Error>

Performs the conversion.
Source§

impl Eq for PasswordHash

Source§

impl StructuralPartialEq for PasswordHash

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.