13 releases (7 breaking)

new 0.9.1 Oct 9, 2024
0.8.0 Sep 26, 2024
0.6.1 Jul 23, 2023
0.1.0 Mar 29, 2023

#306 in Rust patterns

Download history 127/week @ 2024-06-21 50/week @ 2024-06-28 28/week @ 2024-07-05 17/week @ 2024-07-12 15/week @ 2024-07-19 54/week @ 2024-07-26 75/week @ 2024-08-02 60/week @ 2024-08-09 47/week @ 2024-08-16 27/week @ 2024-08-23 28/week @ 2024-08-30 70/week @ 2024-09-06 60/week @ 2024-09-13 738/week @ 2024-09-20 444/week @ 2024-09-27 194/week @ 2024-10-04

1,450 downloads per month

GPL-2.0-or-later

135KB
4K SLoC

C 3.5K SLoC // 0.1% comments Rust 534 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.1MB
~42K SLoC