Passgen

Struct Passgen 

Source
pub struct Passgen {
    pub enab_letters: bool,
    pub enab_u_letters: bool,
    pub enab_num: bool,
    pub enab_spec_symbs: bool,
    pub enab_strong_usab: bool,
    pub custom_charset: &'static str,
    pub password: String,
    pub language: Language,
}
Expand description

Main Passgen structure.

§Examples

You can create a token that includes lowercase letters and numbers up to 30 characters long:

use passgenlib::Passgen;
let result = Passgen::new().set_enabled_letters(true).set_enabled_numbers(true).generate(30);

You can create a default strong password including all literals, numbers and symbols:

use passgenlib::Passgen;
let result = Passgen::default().generate(12);

You can create a strong and usability password. Including all characters, but the first position in the password is a capital or small letter, the last position is the symbol. 🔸 Excluded ambiguous characters "0oOiIlL1".

use passgenlib::Passgen;
let result = Passgen::default_strong_and_usab().generate(8);

You can create a set from your custom charset:

use passgenlib::Passgen;
let result = Passgen::new().set_custom_charset("bla@.321").generate(8);

You can validate the existing password against the added rules:

use passgenlib::Passgen;
let mut generator = Passgen::default();
generator.set_enabled_letters(true).set_enabled_numbers(true);
generator.set_password("MyP@ssw0rd");
assert!(generator.validate_password());

You can get password strength score:

use passgenlib::Passgen;
let mut generator = Passgen::default();
generator.set_password("MyP@ssw0rd");
let score = generator.password_strength_score();
assert!(score >= 0 && score <= 100);

You can get password strength level in multiple languages:

use passgenlib::Passgen;
use passgenlib::lang::lang::{Language, StrengthTranslations};
let mut generator = Passgen::default();
generator.set_password("MyP@ssw0rd");

// English (default)
assert_eq!(generator.password_strength_level(), "Strong");

// Russian
generator.set_language(Language::Russian);
assert_eq!(generator.password_strength_level(), "Сильный");

// Spanish
generator.set_language(Language::Spanish);
assert_eq!(generator.password_strength_level(), "Fuerte");

You can generate password and immediately get its strength score:

use passgenlib::Passgen;
let mut generator = Passgen::default();
let password = generator.generate(12);

// The generated password is stored in the password field
assert_eq!(generator.get_password(), password);

// You can immediately get the strength score
let score = generator.password_strength_score();
assert!(score > 0);

Fields§

§enab_letters: bool

Presence of letters.

§enab_u_letters: bool

Presence of a capital letters.

§enab_num: bool

Presence of numeric characters.

§enab_spec_symbs: bool

Presence of special characters.

§enab_strong_usab: bool

Including all characters, but the first position in the password is a capital or small letter, the last position is the symbol. Excluded ambiguous characters "0oOiIlL1".

⚠️ If this rule is enabled, the other consistency rules of the generating are not taken, except for a rule custom_charset.

§custom_charset: &'static str

User defined character set.

⚠️This set of characters will exclude all other rules except for a rule "enab_strong_usab".

⚙️If "enab_strong_usab" on too then you can generate combined strong and usability result with custom charset.

§password: String

Current password stored for validation and strength checking. This field is automatically populated when using the generate() method or manually set using the set_password() method.

§language: Language

Language for password strength level descriptions. Default is English.

Implementations§

Source§

impl Passgen

Source

pub fn new() -> Passgen

Get an instance of Passgen without any rules.

Source

pub fn default() -> Passgen

Set default ruleset of Passgen to “all simple rules are enabled”.

Source

pub fn default_strong_and_usab() -> Passgen

Set default ruleset of Passgen to “Strong & usability”.

Including all characters, but the first position in the password is a capital or small letter, the last position is the symbol. Excluded ambiguous characters "0oOiIlL1".

⚠️ If this rule is enabled, the other consistency rules of the generating are not taken, except for a rule custom_charset.

Source

pub fn set_enabled_letters(&mut self, value: bool) -> &mut Passgen

Set value of the field enab_letters for Passgen.

Source

pub fn set_enabled_uppercase_letters(&mut self, value: bool) -> &mut Passgen

Set value of the field enab_u_letters for Passgen.

Source

pub fn set_enabled_numbers(&mut self, value: bool) -> &mut Passgen

Set value of the field enab_num for Passgen.

Source

pub fn set_enabled_spec_symbols(&mut self, value: bool) -> &mut Passgen

Set value of the field enab_spec_symbs for Passgen.

Source

pub fn set_enabled_strong_usab(&mut self, value: bool) -> &mut Passgen

Set value of the field enab_strong_usab for Passgen.

Including all characters, but the first position in the password is a capital or small letter, the last position is the symbol. Excluded ambiguous characters "0oOiIlL1".

⚠️ If this rule is enabled, the other consistency rules of the generating are not taken, except for a rule custom_charset.

Source

pub fn set_custom_charset(&mut self, value: &'static str) -> &mut Passgen

Set user defined character set. You can use any Unicode characters and emoji. For example: abcABC123⭕➖❎⚫⬛n₼⁂🙂

⚠️This set of characters will exclude all other rules except for a rule "enab_strong_usab".

⚙️If "enab_strong_usab" on too then you can generate combined strong and usability result with custom charset.

Source

pub fn set_password(&mut self, password: &str) -> &mut Passgen

Set password for validation and strength checking. This method is useful when you want to validate or check the strength of an existing password.

Source

pub fn get_password(&self) -> &str

Get current password. Returns the password that was either generated using generate() method or set using set_password() method.

Source

pub fn set_language(&mut self, language: Language) -> &mut Passgen

Set language for password strength level descriptions.

Source

pub fn generate(&mut self, length: u32) -> String

Generate result. Argument “length” will not be less than 4. The generated password is automatically stored in the password field for immediate validation or strength checking.

Source

pub fn validate_password(&self) -> bool

Validate if the current password matches the configured rules.

Source

pub fn password_strength_score(&self) -> u8

Calculate password strength score (0-100). Based on multiple factors: length, character variety, entropy, and common patterns.

Source

pub fn password_strength_level(&self) -> &'static str

Get password strength level description in the selected language.

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.
Source§

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

Source§

fn vzip(self) -> V