pub struct PasswordRequirements {
pub length: u16,
pub decimal: u16,
pub specials: u16,
pub first_is_letter: bool,
pub allow_repeats: bool,
}Expand description
A structure to describe password requirements.
Fields§
§length: u16The length of the password.
decimal: u16How many decimal integer characters should the password contain?
specials: u16How many special characters should the password contain?
first_is_letter: boolShould the first character always be a letter?
allow_repeats: boolAllow characters to be used more than once?
Implementations§
Source§impl PasswordRequirements
impl PasswordRequirements
Sourcepub fn validate(&self) -> Self
pub fn validate(&self) -> Self
Validates the instance’s values.
This returns a mutated copy of the instance where the values satisfy “sane minimum requirements” suitable for any password.
The phrase “sane minimum requirements” implies
-
lengthis not less than 10 -
To avoid repetitions,
lengthis not more than- 52 if only letters (no decimal integers or special characters) are used
- 62 if only letters and decimal integers are used
- 68 if only letters and special characters are used
- 78 if letters, decimal integers, and special characters are used
- u16::MAX if repeated characters are allowed
-
specialscharacter count does not overrule the required number of- letters (2; 1 uppercase and 1 lowercase)
- decimal integers (if
decimalis specified as non-zero value)
-
decimalcharacter count does not overrule the required number of- letters (2; 1 uppercase and 1 lowercase)
- special characters (if
specialsis specified as non-zero value)
§About resolving conflicts
If this function finds a conflict between the specified number of
specials characters and decimal, then decimal integers takes precedence.
For example:
use mk_pass::PasswordRequirements;
let req = PasswordRequirements {
length: 16,
specials: 16,
decimal: 16,
..Default::default()
};
let expected = PasswordRequirements {
length: 16,
specials: 1,
decimal: 13,
..Default::default()
};
assert_eq!(req.validate(), expected);Trait Implementations§
Source§impl Clone for PasswordRequirements
impl Clone for PasswordRequirements
Source§fn clone(&self) -> PasswordRequirements
fn clone(&self) -> PasswordRequirements
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more