Struct tag_password::Password

source ·
pub struct Password<T: ?Sized>(/* private fields */);
Expand description

Represents password data that can be hashed and verified.

This struct encapsulates password data and supports hashing with the hash function, which can be enabled with the argon2 feature. It also provides verification functionality via the verify function.

Implementations§

source§

impl<T: ?Sized> Password<T>

source

pub fn new(value: impl Into<String>) -> Self

Creates a new Password instance from the provided value.

Arguments
  • value: A value that can be converted into a String.

Returns a new Password instance with the provided value.

source

pub fn as_bytes(&self) -> &[u8]

Retrieves the byte representation of the password value.

Returns a slice containing the bytes representing the password.

source§

impl Password<Plain>

source

pub unsafe fn as_hashed(self) -> Password<Hashed>

Converts a plain text password into a hashed password.

Returns a new Password instance containing the hashed password.

source

pub fn hash<'a>( &self, argon2: Option<Argon2<'_>>, salt: impl Into<Salt<'a>> ) -> Result<Password<Hashed>>

Hashes the password using Argon2 (if the ‘argon2’ feature is enabled).

  • argon2: An optional Argon2 configuration.
  • salt: A salt value used for hashing.

Produces a result containing a new Password instance with the hashed value if successful. If hashing fails, an argon2::password_hash::Result with an error is returned.

source§

impl Password<Hashed>

source

pub unsafe fn as_plain(self) -> Password<Plain>

Unsafely converts a hashed password into a plain text password. This operation is marked as unsafe because once a password is hashed, it cannot be converted back to plain text.

Returns a new Password instance containing the plain text password.

source

pub fn verify( &self, argon2: Option<Argon2<'_>>, plain: impl Into<Password<Plain>> ) -> Result<()>

Verifies if the hashed password matches the provided plain text password.

  • argon2: An optional Argon2 configuration.
  • plain: A plain text password used for verification.

Returns a result indicating success or failure of the verification process. If successful, Ok(()) is returned. If verification fails, an argon2::password_hash::Result with an error is returned.

Trait Implementations§

source§

impl<T: Clone + ?Sized> Clone for Password<T>

source§

fn clone(&self) -> Password<T>

Returns a copy 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<T: ?Sized> Debug for Password<T>

source§

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

Formats the Password for debugging purposes.

source§

impl<'de, T: ?Sized> Deserialize<'de> for Password<T>

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: ?Sized> Display for Password<T>

source§

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

Formats the Password for displaying purposes.

source§

impl<T: ?Sized> From<String> for Password<T>

source§

fn from(value: String) -> Self

Converts the String instance to a Password.

source§

impl<T: ?Sized> Into<String> for Password<T>

source§

fn into(self) -> String

Converts the Password instance into a String.

source§

impl<T: PartialEq + ?Sized> PartialEq for Password<T>

source§

fn eq(&self, other: &Password<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: ?Sized> Serialize for Password<T>

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq + ?Sized> Eq for Password<T>

source§

impl<T: ?Sized> StructuralEq for Password<T>

source§

impl<T: ?Sized> StructuralPartialEq for Password<T>

Auto Trait Implementations§

§

impl<T: ?Sized> RefUnwindSafe for Password<T>
where T: RefUnwindSafe,

§

impl<T: ?Sized> Send for Password<T>
where T: Send,

§

impl<T: ?Sized> Sync for Password<T>
where T: Sync,

§

impl<T: ?Sized> Unpin for Password<T>
where T: Unpin,

§

impl<T: ?Sized> UnwindSafe for Password<T>
where T: UnwindSafe,

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> 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<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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§

default 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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,