pval

Crates.iopval
lib.rspval
version0.1.1
created_at2025-03-07 19:07:51.690836+00
updated_at2025-03-07 19:14:43.091259+00
descriptionA Rust library for password validation with customizable criteria.
homepagehttps://github.com/91dns/pval
repositoryhttps://github.com/91dns/pval
max_upload_size
id1583515
size10,470
Dennis (91dns)

documentation

https://docs.rs/pval

README

Installation

Add pval to your Cargo.toml:

[dependencies]
pval = "0.1.0"

Or you can add it via the command line:

cargo add pval

Usage

Here's an example of how to use pval:

use pval::Pval;

fn main() -> Result<(), String> {
    let validator = Pval::new()
        .min_length(8)
        .require_uppercase(true)
        .require_lowercase(true)
        .require_digit(true)
        .require_special(true)
        .build();

    let password = "P@ssw0rd";

    validator.validate(password)?;
    println!("Password is valid.");

    Ok(())
}

You can also load passwords from a file and validate them:

use pval::Pval;
use pval::utils::load_passwords;

fn main() -> Result<(), std::io::Error> {
    let validator = Pval::new()
        .min_length(8)
        .require_uppercase(true)
        .require_lowercase(true)
        .require_digit(true)
        .require_special(true)
        .build();

    let passwords = load_passwords("passwords.txt")?;

    for password in passwords {
        match validator.validate(&password) {
            Ok(_) => println!("Password '{}' is valid.", password),
            Err(e) => println!("Password '{}' is invalid: {}", password, e),
        }
    }

    Ok(())
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Commit count: 20

cargo fmt