pub struct PasswordHasher { /* private fields */ }Expand description
Argon2id password hashing service.
Construct with PasswordConfig (or use Default for OWASP-recommended settings),
register with app.service(hasher), and extract in handlers via
modo::Service<PasswordHasher>.
Both hash_password and
verify_password run on a blocking thread
via tokio::task::spawn_blocking to avoid stalling the async runtime.
Implementations§
Source§impl PasswordHasher
impl PasswordHasher
Sourcepub fn new(config: PasswordConfig) -> Result<Self, Error>
pub fn new(config: PasswordConfig) -> Result<Self, Error>
Create a new hasher with the given Argon2id parameters.
Returns an error if the parameter values are invalid (e.g., zero memory or parallelism).
Sourcepub async fn hash_password(&self, password: &str) -> Result<String, Error>
pub async fn hash_password(&self, password: &str) -> Result<String, Error>
Hash a password using Argon2id with a random salt.
Returns a PHC-formatted string that embeds the algorithm, parameters, salt, and hash. Each call produces a unique output even for the same input.
Runs on a blocking thread to avoid stalling the Tokio runtime.
Sourcepub async fn verify_password(
&self,
password: &str,
hash: &str,
) -> Result<bool, Error>
pub async fn verify_password( &self, password: &str, hash: &str, ) -> Result<bool, Error>
Verify a password against a PHC-formatted hash string.
Returns Ok(true) on match, Ok(false) on mismatch.
Returns Err only for malformed hash strings.
The parameters embedded in the hash are used for verification, not the parameters this hasher was constructed with.
Runs on a blocking thread to avoid stalling the Tokio runtime.
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 moreSource§impl Debug for PasswordHasher
impl Debug for PasswordHasher
Auto 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<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> DefaultHooks for T
impl<T> DefaultHooks for T
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