pub struct PasswordGenerator { /* private fields */ }
Expand description

PasswordGenerator struct for generatoring passwords

Implementations§

PasswordGenerator Constructor

Builder function for setting password length

Examples
use simple_password_generator::PasswordGenerator;

let expected_length = 16;
let result = PasswordGenerator::new().length(expected_length).generate();

assert_eq!(expected_length as usize, result.chars().count());

Builder function for setting lowercase characters only

Examples
use simple_password_generator::PasswordGenerator;

let test_password = PasswordGenerator::new().lowercase_only(true).generate();
let mut contains_uppercase = false;

for c in test_password.chars() {
	if c.is_alphabetic() {
		if c.is_uppercase() {
			contains_uppercase = true
		}
	}
}

assert_eq!(false, contains_uppercase);

Builder function for setting uppercase characters only

Examples
use simple_password_generator::PasswordGenerator;

let test_password = PasswordGenerator::new().uppercase_only(true).generate();
let mut contains_lowercase = false;

for c in test_password.chars() {
	if c.is_alphabetic() {
		if c.is_lowercase() {
			contains_lowercase = true
		}
	}
}

assert_eq!(false, contains_lowercase);

Builder function for excluding any numbers from password

Examples
use simple_password_generator::PasswordGenerator;

let test_password = PasswordGenerator::new().exclude_numbers(true).generate();
let mut contains_numbers = false;

for c in test_password.chars() {
	if c.is_numeric() {
		contains_numbers = true
	}
}

assert_eq!(false, contains_numbers);

Builder function for excluding any special characters from password

Examples
use simple_password_generator::PasswordGenerator;

let test_password = PasswordGenerator::new()
	.exclude_special_chars(true)
	.generate();
let spec_char_vec: Vec<char> = vec!['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '~'];
let mut contains_special_chars = false;

for c in test_password.chars() {
	if spec_char_vec.contains(&c) {
		contains_special_chars = true;
	}
}

assert_eq!(false, contains_special_chars);

Generates a password

Examples
use simple_password_generator::PasswordGenerator;

let password = PasswordGenerator::new().generate();

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.