14 releases (7 breaking)

0.9.2 Oct 17, 2024
0.9.0 Sep 29, 2024
0.6.1 Jul 23, 2023
0.1.0 Mar 29, 2023

#183 in Authentication

Download history 33/week @ 2024-08-17 31/week @ 2024-08-24 30/week @ 2024-08-31 79/week @ 2024-09-07 47/week @ 2024-09-14 846/week @ 2024-09-21 353/week @ 2024-09-28 227/week @ 2024-10-05 265/week @ 2024-10-12 81/week @ 2024-10-19 130/week @ 2024-10-26 149/week @ 2024-11-02 167/week @ 2024-11-09 147/week @ 2024-11-16 3/week @ 2024-11-23 82/week @ 2024-11-30

429 downloads per month

GPL-2.0-or-later

140KB
4K SLoC

C 3.5K SLoC // 0.1% comments Rust 547 SLoC // 0.0% comments

libpwquality bindings for Rust

Crates.io Crates.io License docs.rs Build Status

Usage

cargo add libpwquality

Example

use libpwquality::{PWQError, PWQuality};

fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}

Cargo features

  • vX_Y_Z: Build with system libpwquality version X.Y.Z. v1_0 Enabled by default.

  • vendored: Build with vendored libpwquality. This requires cracklib to be installed. You can also set CRACKLIB_INCLUDE_PATH and CRACKLIB_LIBRARY_PATH environment variables to specify the include path and library path. Disabled by default.

  • vendored-cracklib: Build with vendored libpwquality and cracklib. The build script will try to guess the path of cracklib dictionaries, but you can set DEFAULT_CRACKLIB_DICT environment variable to override it. Disabled by default.

Dependencies

~0–2.2MB
~46K SLoC