pub struct PasswordHasher { /* private fields */ }Expand description
Stateless hasher — owns one Argon2 context preconfigured with
the active parameters. Cheap to clone (the inner Argon2<'static>
holds borrowed references to the static parameter struct only).
Implementations§
Source§impl PasswordHasher
impl PasswordHasher
Sourcepub fn with_params(params: Params) -> Self
pub fn with_params(params: Params) -> Self
Construct with explicit Argon2id parameters. Use the Default
impl for the standard cost; reach for this only when tuning to
non-standard hardware (e.g. a mobile-only deployment).
Sourcepub fn hash(&self, plaintext: &str) -> Result<String>
pub fn hash(&self, plaintext: &str) -> Result<String>
Hash a plaintext password. The returned PHC string is what
crate::store::UserStore::set_password_hash persists.
The salt is sourced from rand::rng() (which delegates to the
OS getrandom under the hood) so we don’t need to depend on
password-hash’s rand_core 0.6 + getrandom feature pair just
for the salt — rand 0.9 is already a direct dependency.
Sourcepub fn verify(&self, plaintext: &str, phc: &str) -> Result<bool>
pub fn verify(&self, plaintext: &str, phc: &str) -> Result<bool>
Verify a plaintext password against a stored PHC hash.
Returns:
Ok(true)if the password matches.Ok(false)if the password is wrong (but the stored hash parsed cleanly).Err(Error::Backend(_))if the stored hash is malformed.
Sourcepub fn needs_rehash(&self, phc: &str) -> Result<bool>
pub fn needs_rehash(&self, phc: &str) -> Result<bool>
Returns true when the stored hash was produced with parameters
that differ from the current configuration. Callers should
re-hash on the next successful login so the user’s stored hash
drifts forward as we ratchet the cost.
Trait Implementations§
Source§impl Clone for PasswordHasher
impl Clone for PasswordHasher
Source§fn clone(&self) -> PasswordHasher
fn clone(&self) -> PasswordHasher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PasswordHasher
impl RefUnwindSafe for PasswordHasher
impl Send for PasswordHasher
impl Sync for PasswordHasher
impl Unpin for PasswordHasher
impl UnsafeUnpin for PasswordHasher
impl UnwindSafe for PasswordHasher
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more