Crates.io | ferropassgen |
lib.rs | ferropassgen |
version | 1.0.2 |
source | src |
created_at | 2024-03-09 07:45:29.099462 |
updated_at | 2024-03-09 07:45:29.099462 |
description | A library for generating secure passwords and passphrases |
homepage | |
repository | https://github.com/JamesClarke7283/FerroPassGen |
max_upload_size | |
id | 1167651 |
size | 17,418 |
ferropassgen
is a Rust library for generating strong and secure passwords and
passphrases. It provides a flexible and customizable password generation
framework that can be easily integrated into other Rust projects.
To use ferropassgen
in your Rust project, add the following to your
Cargo.toml
:
[dependencies]
ferropassgen = "0.1.0"
Then, import the necessary modules and structs in your Rust code:
use ferropassgen::{PassGen, PasswordGen, PassphraseGen, PassGenError};
To generate a password, create an instance of PasswordGen
and call the
generate
method:
let length = 16;
let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*".chars().collect::<Vec<char>>();
let password_gen = PasswordGen::new(length, charset, None, None)?;
let password = password_gen.generate();
To generate a passphrase, create an instance of PassphraseGen
and call the
generate
method:
let length = 4;
let wordlist = vec!["apple", "banana", "cherry", "date", "elderberry"]
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>();
let separator = Some('_');
let word_case = Some(true);
let passphrase_gen = PassphraseGen::new(length, wordlist, separator, word_case)?;
let passphrase = passphrase_gen.generate();
The new
methods of PasswordGen
and PassphraseGen
return a
Result<Self, PassGenError>
. Make sure to handle the potential errors
appropriately.
Here are a few examples of using ferropassgen
to generate passwords and
passphrases:
use ferropassgen::{PassGen, PasswordGen, PassphraseGen};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate a 20-character password with a custom character set
let length = 20;
let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".chars().collect::<Vec<char>>();
let password_gen = PasswordGen::new(length, charset, None, None)?;
let password = password_gen.generate();
println!("Generated Password: {}", password);
// Generate a passphrase with 5 words, separated by underscores, and in uppercase
let length = 5;
let wordlist = vec!["apple", "banana", "cherry", "date", "elderberry"]
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>();
let separator = Some('_');
let word_case = Some(true);
let passphrase_gen = PassphraseGen::new(length, wordlist, separator, word_case)?;
let passphrase = passphrase_gen.generate();
println!("Generated Passphrase: {}", passphrase);
Ok(())
}
For detailed information about the ferropassgen
API, including structs,
traits, and methods, please refer to the
API documentation.
This project is licensed under the GNU Lesser General Public License v3.0.
ferropassgen
was inspired by the need for a flexible and customizable password
generation library in Rust. It builds upon the excellent work of the Rust
community and the libraries they have created.
Special thanks to the developers of the following libraries: