Struct PasswordMaker

Source
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

Source

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);
Source

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

Source§

fn clone(&self) -> PasswordMaker

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 PasswordMaker

Source§

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

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

impl Default for PasswordMaker

Source§

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§

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