pub struct PasswordGenerator { /* private fields */ }
Expand description
PasswordGenerator struct for generatoring passwords
Implementations§
source§impl PasswordGenerator
impl PasswordGenerator
sourcepub fn new() -> PasswordGenerator
pub fn new() -> PasswordGenerator
PasswordGenerator Constructor
sourcepub fn length(self, length: u8) -> Self
pub fn length(self, length: u8) -> Self
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());
sourcepub fn lowercase_only(self, lowercase_only: bool) -> Self
pub fn lowercase_only(self, lowercase_only: bool) -> Self
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);
sourcepub fn uppercase_only(self, uppercase_only: bool) -> Self
pub fn uppercase_only(self, uppercase_only: bool) -> Self
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);
sourcepub fn exclude_numbers(self, exclude_numbers: bool) -> Self
pub fn exclude_numbers(self, exclude_numbers: bool) -> Self
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);
sourcepub fn exclude_special_chars(self, exclude_special_chars: bool) -> Self
pub fn exclude_special_chars(self, exclude_special_chars: bool) -> Self
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);