PasswordRequirements

Struct PasswordRequirements 

Source
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: u16

The length of the password.

§decimal: u16

How many decimal integer characters should the password contain?

§specials: u16

How many special characters should the password contain?

§first_is_letter: bool

Should the first character always be a letter?

§allow_repeats: bool

Allow characters to be used more than once?

Implementations§

Source§

impl PasswordRequirements

Source

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

  1. length is not less than 10

  2. To avoid repetitions, length is 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
  3. specials character count does not overrule the required number of

    • letters (2; 1 uppercase and 1 lowercase)
    • decimal integers (if decimal is specified as non-zero value)
  4. decimal character count does not overrule the required number of

    • letters (2; 1 uppercase and 1 lowercase)
    • special characters (if specials is 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

Source§

fn clone(&self) -> PasswordRequirements

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PasswordRequirements

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PasswordRequirements

Source§

fn default() -> Self

Create default password requirements.

Source§

impl PartialEq for PasswordRequirements

Source§

fn eq(&self, other: &PasswordRequirements) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PasswordRequirements

Source§

impl Eq for PasswordRequirements

Source§

impl StructuralPartialEq for PasswordRequirements

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V