pub struct PasswordMaker {
pub length: u32,
pub exclude_similar: bool,
pub include_whitespace_in_candidate: bool,
pub lowercase: Classifier,
pub uppercase: Classifier,
pub number: Classifier,
pub symbol: Classifier,
pub others: Vec<Classifier>,
}
Expand description
Password generator
You can specify the following for the generated password:
- Length
- Whether to include similar characters
- Whether to include whitespace
- Candidates for uppercase, lowercase, numbers, symbols, and other characters
- Minimum number of characters for each type
Fields§
§length: u32
Length of the password
exclude_similar: bool
Exclude similar characters (‘i’, ‘l’, ‘1’, ‘o’, ‘0’, ‘O’) from the password
include_whitespace_in_candidate: bool
Include whitespace in the candidate characters for the password
lowercase: Classifier
Settings for lowercases
uppercase: Classifier
Settings for uppercases
number: Classifier
Settings for numbers
symbol: Classifier
Settings for symbols
others: Vec<Classifier>
Settings for other characters
Implementations§
Source§impl PasswordMaker
impl PasswordMaker
Sourcepub fn generate(&mut self) -> Result<String, String>
pub fn generate(&mut self) -> Result<String, String>
Generate a password
Generates a password according to the settings of the password generator. Returns an error if there is an issue with the settings.
Issues include:
- No candidates for a character type, but the minimum number of characters is set to 1 or more
- The total minimum number of characters for all types exceeds the password length
§Returns
- Ok: Password
- Err: Error message
§Errors
- No candidates for a character type, but the minimum number of characters is set to 1 or more
- The total minimum number of characters for all types exceeds the password length
- No candidates for the password
- The password length is 0
§Examples
use password_maker::PasswordMaker;
let mut password_maker = PasswordMaker::default();
let password = password_maker.generate().unwrap();
println!("{}", password);
Sourcepub fn candidates(&self) -> Vec<String>
pub fn candidates(&self) -> Vec<String>
Return a list of candidate characters for the password according to the settings of the password generator
§Returns
- List of candidate characters for the password
§Examples
use password_maker::PasswordMaker;
let password_maker = PasswordMaker::default();
let candidates = password_maker.candidates();
println!("{:?}", candidates);
Trait Implementations§
Source§impl Clone for PasswordMaker
impl Clone for PasswordMaker
Source§fn clone(&self) -> PasswordMaker
fn clone(&self) -> PasswordMaker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PasswordMaker
impl Debug for PasswordMaker
Source§impl Default for PasswordMaker
impl Default for PasswordMaker
Source§fn default() -> Self
fn default() -> Self
Create a password generator with default settings
The default settings are as follows:
- length: 16
- exclude_similar: false
- include_whitespace_in_candidate: false
- lowercase_letters
- candidates: a-z
- min: 1
- uppercase_letters
- candidates: A-Z
- min: 1
- numbers:
- candidates: 0-9
- min: 1
- symbols:
- candidates: ! “ # $ % & ’ ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
- min: 1
- other_characters:
- candidates: None
- min: 0
Auto Trait Implementations§
impl Freeze for PasswordMaker
impl RefUnwindSafe for PasswordMaker
impl Send for PasswordMaker
impl Sync for PasswordMaker
impl Unpin for PasswordMaker
impl UnwindSafe for PasswordMaker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more