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>
impl<T: ?Sized> Password<T>
source§impl Password<Plain>
impl Password<Plain>
sourcepub unsafe fn as_hashed(self) -> Password<Hashed>
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.
sourcepub fn hash<'a>(
&self,
argon2: Option<Argon2<'_>>,
salt: impl Into<Salt<'a>>
) -> Result<Password<Hashed>>
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 optionalArgon2
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>
impl Password<Hashed>
sourcepub unsafe fn as_plain(self) -> Password<Plain>
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.
sourcepub fn verify(
&self,
argon2: Option<Argon2<'_>>,
plain: impl Into<Password<Plain>>
) -> Result<()>
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 optionalArgon2
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.