#password-hashing #thread-pool #worker #shared-state #run-time #rayon #operations

deprecated axum-password-worker

A wrapper for password hashing that can be used as shared state, and uses a rayon thread pool so it won't block the async runtime

8 unstable releases (3 breaking)

0.4.1 Aug 24, 2023
0.4.0 Aug 22, 2023
0.3.3 Apr 9, 2023
0.2.0 Apr 8, 2023
0.1.0 Apr 5, 2023

#28 in #shared-state

MIT license

16KB
163 lines

DEPRECATED: Switched the crate name to password-worker

Crates IO: https://crates.io/crates/password-worker

GitHub: https://github.com/junderw/password-worker

axum-password-worker Latest Version

A module providing a password hashing and verification worker.

This module contains the PasswordWorker struct, which manages hashing and verification operations using a combination of a rayon thread pool and crossbeam-channel to efficiently handle these operations asynchronously. It also makes use of a tokio::sync::oneshot channel but does not require the tokio runtime to be present.

The methods will not block the async runtime. All await operations do not block. They use non-blocking channel implementations to send and receive passwords and hashes to the rayon thread pool.

PasswordWorker is Send + Sync + Clone, and contains no lifetimes. The Clone implementation is a shallow copy that "points" to the same thread pool. It can be used as shared state without an Arc. All methods take &self so a Mutex is also not necessary.

Add as Dependency

cargo add axum-password-worker

## OR if you want to also add argon2 support

cargo add axum-password-worker -F rust-argon2

Example

use axum_password_worker::{BcryptConfig, PasswordWorker};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let password = "hunter2";
    let cost = 12; // bcrypt cost value
    let max_threads = 4; // rayon thread pool max threads
    let password_worker = PasswordWorker::new_bcrypt(max_threads)?;

    let hashed_password = password_worker.hash(password, BcryptConfig { cost }).await?;
    println!("Hashed password: {:?}", hashed_password);

    let is_valid = password_worker.verify(password, hashed_password).await?;
    println!("Verification result: {:?}", is_valid);

    Ok(())
}

Available feature flags

There are some implementations included in the library. Each is tied to optional dependency features.

  • bcrypt - (default) (dependency), exports the Bcrypt and BcryptConfig types.
  • rust-argon2 - (dependency), exports the Argon2id and Argon2idConfig types.

Dependencies

~4–11MB
~110K SLoC