Struct psph::Password

source ·
#[non_exhaustive]
pub struct Password { /* private fields */ }
Expand description

A random password / passphrase generator. The generated password is a string of three words separated by hyphens. Each word is between 6 and 8 characters long. The first character of each word is capitalized.

Implementations§

source§

impl Password

source

pub fn entropy(&self) -> f64

Calculates the entropy of a password based on its length, the number of unique characters used in the password and the number of bits of the hash generated from the password.

Arguments
  • &self - An immutable reference to the password.
Returns
  • f64 - The calculated entropy of the password.
Entropy Ranges

The following ranges can give you an idea of how the entropy is considered:

  • Poor: less than 40 bits
  • Weak: 40-55 bits
  • Reasonable: 56-70 bits
  • Strong: 71-80 bits
  • Excellent: 81 bits and above

Keep in mind that these values are just rough estimates and the actual entropy of a password depends on the distribution of characters used in the password and the number of unique characters in it, and not just its length.

source

pub fn hash(&self) -> String

Returns the hash of the generated passphrase.

source

pub fn hash_length(&self) -> usize

Returns the hash length.

source

pub fn is_empty(&self) -> bool

Returns true if the generated passphrase is empty. Returns false if the generated passphrase is not empty.

source

pub fn len(&self) -> usize

Returns the length of the generated passphrase.

source

pub fn new(len: u8, separator: &str, special_chars: Vec<char>) -> Self

Returns the generated passphrase.

source

pub fn passphrase(&self) -> &str

Returns the generated passphrase.

source

pub fn password_length(&self) -> usize

Returns the password length.

source

pub fn set_passphrase(&mut self, passphrase: &str)

Sets the generated passphrase.

Trait Implementations§

source§

impl Clone for Password

source§

fn clone(&self) -> Password

Returns a copy 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 Password

source§

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

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

impl Default for Password

source§

fn default() -> Self

Default to a passphrase of 4 words.

source§

impl Display for Password

source§

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

Display the generated passphrase.

source§

impl PartialEq<Password> for Password

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Password> for Password

source§

fn partial_cmp(&self, other: &Password) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StructuralPartialEq for Password

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
T: Clone,

§

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> ToString for Twhere
T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V