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: boolPresence of letters.
enab_u_letters: boolPresence of a capital letters.
enab_num: boolPresence of numeric characters.
enab_spec_symbs: boolPresence of special characters.
enab_strong_usab: boolIncluding 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 strUser 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: StringCurrent 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: LanguageLanguage for password strength level descriptions. Default is English.
Implementations§
Source§impl Passgen
impl Passgen
Sourcepub fn default_strong_and_usab() -> Passgen
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.
Sourcepub fn set_enabled_letters(&mut self, value: bool) -> &mut Passgen
pub fn set_enabled_letters(&mut self, value: bool) -> &mut Passgen
Set value of the field enab_letters for Passgen.
Sourcepub fn set_enabled_uppercase_letters(&mut self, value: bool) -> &mut Passgen
pub fn set_enabled_uppercase_letters(&mut self, value: bool) -> &mut Passgen
Set value of the field enab_u_letters for Passgen.
Sourcepub fn set_enabled_numbers(&mut self, value: bool) -> &mut Passgen
pub fn set_enabled_numbers(&mut self, value: bool) -> &mut Passgen
Set value of the field enab_num for Passgen.
Sourcepub fn set_enabled_spec_symbols(&mut self, value: bool) -> &mut Passgen
pub fn set_enabled_spec_symbols(&mut self, value: bool) -> &mut Passgen
Set value of the field enab_spec_symbs for Passgen.
Sourcepub fn set_enabled_strong_usab(&mut self, value: bool) -> &mut Passgen
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.
Sourcepub fn set_custom_charset(&mut self, value: &'static str) -> &mut Passgen
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.
Sourcepub fn set_password(&mut self, password: &str) -> &mut Passgen
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.
Sourcepub fn get_password(&self) -> &str
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.
Sourcepub fn set_language(&mut self, language: Language) -> &mut Passgen
pub fn set_language(&mut self, language: Language) -> &mut Passgen
Set language for password strength level descriptions.
Sourcepub fn generate(&mut self, length: u32) -> String
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.
Sourcepub fn validate_password(&self) -> bool
pub fn validate_password(&self) -> bool
Validate if the current password matches the configured rules.
Sourcepub fn password_strength_score(&self) -> u8
pub fn password_strength_score(&self) -> u8
Calculate password strength score (0-100). Based on multiple factors: length, character variety, entropy, and common patterns.
Sourcepub fn password_strength_level(&self) -> &'static str
pub fn password_strength_level(&self) -> &'static str
Get password strength level description in the selected language.