pub struct PasswordWorker<H: Hasher> { /* private fields */ }
Expand description
A worker that handles password hashing and verification using a rayon
thread pool
and crossbeam-channel
.
The PasswordWorker
struct provides asynchronous password hashing and verification
operations.
Implementations§
Source§impl PasswordWorker<Argon2id>
impl PasswordWorker<Argon2id>
Sourcepub fn new_argon2id(
max_threads: usize,
) -> Result<Self, PasswordWorkerError<Argon2id>>
Available on crate feature rust-argon2
only.
pub fn new_argon2id( max_threads: usize, ) -> Result<Self, PasswordWorkerError<Argon2id>>
rust-argon2
only.This constructor creates a new argon2id instance
Source§impl PasswordWorker<Bcrypt>
impl PasswordWorker<Bcrypt>
Sourcepub fn new_bcrypt(
max_threads: usize,
) -> Result<Self, PasswordWorkerError<Bcrypt>>
Available on crate feature bcrypt
only.
pub fn new_bcrypt( max_threads: usize, ) -> Result<Self, PasswordWorkerError<Bcrypt>>
bcrypt
only.This constructor creates a new bcrypt instance
Source§impl<H: Hasher> PasswordWorker<H>
impl<H: Hasher> PasswordWorker<H>
Sourcepub fn new(max_threads: usize) -> Result<Self, PasswordWorkerError<H>>
pub fn new(max_threads: usize) -> Result<Self, PasswordWorkerError<H>>
Creates a new PasswordWorker
with the given maximum number of threads.
The max_threads
parameter specifies the maximum number of threads the worker can use.
§Examples
use password_worker::{Bcrypt, PasswordWorker};
let max_threads = 4; // rayon thread pool max threads
let password_worker: PasswordWorker<Bcrypt> = PasswordWorker::new(max_threads)?;
Sourcepub async fn hash(
&self,
password: impl Into<String>,
cost: H::Config,
) -> Result<String, PasswordWorkerError<H>>
pub async fn hash( &self, password: impl Into<String>, cost: H::Config, ) -> Result<String, PasswordWorkerError<H>>
Asynchronously hashes the given password using its hashing algorithm.
§Example
use password_worker::{Bcrypt, BcryptConfig, PasswordWorker};
let password = "hunter2";
let cost = 12; // bcrypt cost value
let max_threads = 4; // rayon thread pool max threads
let password_worker = PasswordWorker::<Bcrypt>::new(max_threads)?;
let hashed_password = password_worker.hash(password, BcryptConfig { cost }).await?;
println!("Hashed password: {:?}", hashed_password);
Sourcepub async fn verify(
&self,
password: impl Into<String>,
hash: impl Into<String>,
) -> Result<bool, PasswordWorkerError<H>>
pub async fn verify( &self, password: impl Into<String>, hash: impl Into<String>, ) -> Result<bool, PasswordWorkerError<H>>
Asynchronously verifies a password against a hash string.
§Example
use password_worker::{Bcrypt, BcryptConfig, PasswordWorker};
let password = "hunter2";
let cost = 12; // bcrypt cost value
let max_threads = 4; // rayon thread pool max threads
let password_worker = PasswordWorker::<Bcrypt>::new(max_threads)?;
let hashed_password = password_worker.hash(password, BcryptConfig { cost }).await?;
let is_valid = password_worker.verify(password, hashed_password).await?;
println!("Verification result: {:?}", is_valid);
Trait Implementations§
Source§impl<H: Clone + Hasher> Clone for PasswordWorker<H>
impl<H: Clone + Hasher> Clone for PasswordWorker<H>
Source§fn clone(&self) -> PasswordWorker<H>
fn clone(&self) -> PasswordWorker<H>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<H> Freeze for PasswordWorker<H>
impl<H> RefUnwindSafe for PasswordWorker<H>
impl<H> Send for PasswordWorker<H>
impl<H> Sync for PasswordWorker<H>
impl<H> Unpin for PasswordWorker<H>
impl<H> UnwindSafe for PasswordWorker<H>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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