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.
Trait Implementations§
source§impl<State: PartialEq> PartialEq for Password<State>
impl<State: PartialEq> PartialEq for Password<State>
impl<State: Eq> Eq for Password<State>
impl<State> StructuralPartialEq for Password<State>
Auto Trait Implementations§
impl<State> Freeze for Password<State>
impl<State> RefUnwindSafe for Password<State>where
State: RefUnwindSafe,
impl<State> Send for Password<State>where
State: Send,
impl<State> Sync for Password<State>where
State: Sync,
impl<State> Unpin for Password<State>where
State: Unpin,
impl<State> UnwindSafe for Password<State>where
State: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more