Struct email_pass::Password
source · pub struct Password<State = Encrypt> { /* private fields */ }Expand description
Safe-access password abstraction.
Implementations§
source§impl Password
impl Password
pub fn new(raw_password: &str) -> Password<Raw>
sourcepub fn from_encrypt(
encrypted_password: &str
) -> Result<Password<Encrypt>, PasswordError>
pub fn from_encrypt( encrypted_password: &str ) -> Result<Password<Encrypt>, PasswordError>
Create an encrypt password, check if password is really hashed.
pub fn verify(&self, raw_password: &Password<Raw>) -> Result<bool, BcryptError>
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Extracts the inner value from Password<Encrypt>.
source§impl Password<Raw>
impl Password<Raw>
sourcepub fn check(self) -> Result<Self, PasswordError>
pub fn check(self) -> Result<Self, PasswordError>
Check the password’s strong, use PasswordStrengthChecker with default values.
If you want change this values, use Password<Raw>::custom_check.
sourcepub fn custom_check(
self,
checker: PasswordStrengthChecker
) -> Result<Self, PasswordError>
pub fn custom_check( self, checker: PasswordStrengthChecker ) -> Result<Self, PasswordError>
Check the password’s strong
Examples
Hard strong password example:
use email_pass::{Password, PasswordStrengthChecker, PasswordStrength};
let checker = PasswordStrengthChecker::new()
.min_len(20)
.strong(PasswordStrength::Hard);
let password_err = Password::new("my.passphrase.0-9").custom_check(checker);
assert!(password_err.is_err());Low strong password example:
use email_pass::{Password, PasswordStrengthChecker, PasswordStrength};
let checker = PasswordStrengthChecker::new()
.min_len(8)
.strong(PasswordStrength::Low);
let raw_password = Password::new("1234567azhc").custom_check(checker);
assert!(raw_password.is_ok());sourcepub fn to_encrypt(self, cost: u32) -> Result<Password<Encrypt>, BcryptError>
pub fn to_encrypt(self, cost: u32) -> Result<Password<Encrypt>, BcryptError>
Transforms Password<Raw> to Password<Encrypt>, encrypting the inner value based in a cost value.
This method not checks the password’s strong.
sourcepub fn to_encrypt_default(self) -> Result<Password<Encrypt>, BcryptError>
pub fn to_encrypt_default(self) -> Result<Password<Encrypt>, BcryptError>
Transforms Password<Raw> to Password<Encrypt>, just encrypting the inner value.
This method not checks the password’s strong.
sourcepub fn to_encrypt_with_cost(
self,
cost: u32
) -> Result<Password<Encrypt>, BcryptError>
pub fn to_encrypt_with_cost( self, cost: u32 ) -> Result<Password<Encrypt>, BcryptError>
Transforms Password<Raw> to Password<Encrypt>, encrypting the inner value based in a cost value.
This method not checks the password’s strong.