#password #pwquality #api-bindings

libpwquality

libpwquality bindings for Rust

7 releases (4 breaking)

0.6.1 Jul 23, 2023
0.6.0 Jul 23, 2023
0.5.1 May 11, 2023
0.5.0 Apr 19, 2023
0.1.0 Mar 29, 2023

#85 in #password

Download history 29/week @ 2024-01-05 17/week @ 2024-01-12 25/week @ 2024-01-19 4/week @ 2024-01-26 34/week @ 2024-02-02 47/week @ 2024-02-09 45/week @ 2024-02-16 15/week @ 2024-02-23 12/week @ 2024-03-01 80/week @ 2024-03-08 8/week @ 2024-03-15 165/week @ 2024-03-29 189/week @ 2024-04-05 303/week @ 2024-04-12 141/week @ 2024-04-19

798 downloads per month

MIT license

295KB
5K SLoC

C 4K SLoC // 0.1% comments Rust 521 SLoC Python 242 SLoC // 0.2% comments Automake 136 SLoC // 0.1% comments Shell 6 SLoC // 0.6% comments Forge Config 4 SLoC

libpwquality bindings for Rust

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

Usage

cargo add libpwquality

libpwquality-rs links system libpwquality library by default, you can optionally enable vendored feature and install cracklib dictionaries to build libpwquality. When the vendored feature is enabled, you can export DEFAULT_CRACKLIB_DICT environment variable to specify the path of the dictionaries if you encounter problems with the dictionary path.

cargo add libpwquality --features vendored
sudo apt-get install cracklib-runtime

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(())
}

Dependencies