PasswordGenerator

Struct PasswordGenerator 

Source
pub struct PasswordGenerator { /* private fields */ }
Expand description

Encapsulates RNG and set of characters. See crate documentation for more.

Implementations§

Source§

impl PasswordGenerator

Source

pub fn new(charset: Vec<char>, length: usize) -> Self

Creates the PasswordGenerator to yield passwords using either PasswordGenerator::generate or PasswordGenerator::generate_n charset will not be deduplicated, so that you could (but should not!) increase the the probability density of the chars in the generated passwords.

Source

pub fn length(self, length: usize) -> Self

Changes the length of the generated passwords, consumes and returns itself.

Source

pub fn generate(&mut self) -> String

Generates one password, with characters randomly chosen from the charset.

Source

pub fn generate_n(&mut self, n: usize) -> Vec<String>

Generates a vector of passwords with length n, calling PasswordGenerator::generate internally. Cannot return an iterator, because that iterator would need to hold a mutable reference to the generator.

Source

pub fn combinations(&self) -> f64

Number of all possible combinations arising from charset and length.

Source

pub fn entropy(&self) -> usize

Entropy of the generated passwords in bits.

Trait Implementations§

Source§

impl Debug for PasswordGenerator

Source§

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

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

impl From<&str> for PasswordGenerator

Source§

fn from(charset: &str) -> PasswordGenerator

Converts to this type from the input type.
Source§

impl From<Vec<char>> for PasswordGenerator

Source§

fn from(charset: Vec<char>) -> PasswordGenerator

Converts to this type from the input type.

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> 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, 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.