#password #password-generator #utility #library

password-maker

Highly customizable password generation library.πŸ”‘

3 releases

0.1.2 Oct 24, 2024
0.1.1 Oct 23, 2024
0.1.0 Oct 23, 2024

#280 in Authentication

22 downloads per month
Used in mkpw

MIT/Apache

56KB
1K SLoC

Password Maker

This is a password generation library for Rust.

Example

Generate a password with the default settings

The default settings are as follows:

use password_maker::PasswordMaker;

fn main() {
    let mut password_maker = PasswordMaker::default();
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => 8m8s]@IV[d=2\f_(
}

Specify the length of the password

You can specify the length of the password as follows:

use password_maker::PasswordMaker;

fn main() {
    let mut password_maker = PasswordMaker {
        length: 20,
        ..Default::default()
    };
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => /(DBnw!pv4@"(ku|)/rx
}

Specify symbols

You can change the symbols as follows:

use password_maker::PasswordMaker;

fn main() {
    let mut password_maker = PasswordMaker::default();
    password_maker.symbol.candidates = vec!["@".to_string(), "^".to_string()];
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => dHt^fO5fzgR@X4EC
}

Specify the minimum number of occurrences

You can specify the minimum number of times a character appears as follows:

use password_maker::PasswordMaker;

fn main() {
    let mut password_maker = PasswordMaker::default();
    password_maker.symbol.minimum_count = 10;
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => ZS^('}):?l}$<$|2
}

Generate a password with only lowercases, excluding symbols, uppercases, and numbers

You can exclude symbols as follows:

use password_maker::PasswordMaker;

fn main() {
    let mut password_maker = PasswordMaker::default();
    password_maker.uppercase.candidates = vec![];
    password_maker.uppercase.minimum_count = 0; // If candidates are empty, min must be 0, otherwise it will result in an error
    password_maker.number.candidates = vec![];
    password_maker.number.minimum_count = 0;
    password_maker.symbol.candidates = vec![];
    password_maker.symbol.minimum_count = 0;
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => tfpwxjzudvaibnwg
}

Add emojis and other characters as candidates

You can add emojis and other characters as candidates as follows:

use password_maker::{Classifier, PasswordMaker};

fn main() {
    let mut password_maker = PasswordMaker {
        others: vec![Classifier {
            candidates: [
                'πŸ˜€', '😁', 'πŸ˜‚', '🀣', 'πŸ˜ƒ', 'πŸ˜„', 'πŸ˜…', 'πŸ˜†', 'πŸ˜‰', '😊', 'πŸ˜‹', '😎', '😍', '😘',
                'πŸ˜—', 'δΈ€', '二', 'δΈ‰', 'ε››', 'δΊ”', 'ε…­', 'δΈƒ', 'ε…«', '九', '十',
            ]
            .iter()
            .map(|&c| c.to_string())
            .collect(),
            minimum_count: 1,
        }],
        ..Default::default()
    };
    let password = password_maker.generate().unwrap();
    println!("{}", password); // => ?🀣-δΊ”πŸ˜7=0*😘r}Nta>
}

License

Licensed under both the Apache License, Version 2.0 and the MIT License.

You may select, at your option, one of the above-listed licenses.

See the LICENSE-APACHE and LICENSE-MIT files for the full text of the Apache License, Version 2.0 and the MIT License, respectively.

Dependencies

~1.5MB
~24K SLoC