pub struct Password {
pub phc: String,
/* private fields */
}Expand description
A safely constructed Password
Fields§
§phc: StringImplementations§
Source§impl Password
impl Password
Sourcepub fn new(phc: &str) -> ResultPwd<Self>
pub fn new(phc: &str) -> ResultPwd<Self>
Load a password from a PCH formatted string. (Use this for load from a Storage)
Sourcepub fn hash(raw: &str, check: impl PasswordIsSafe) -> ResultPwd<Self>
pub fn hash(raw: &str, check: impl PasswordIsSafe) -> ResultPwd<Self>
Hash a raw string into a PCH salted string using recommended algorithm (argon2::Argon2 as 2021) and verify is safe using a checker
Sourcepub unsafe fn hash_unsafe(raw: &str) -> ResultPwd<Self>
pub unsafe fn hash_unsafe(raw: &str) -> ResultPwd<Self>
Hash a raw string into a PCH salted string using recommended algorithm (argon2::Argon2 as 2021)
§Safety
This is marked unsafe because allow to use empty string, short password, leaked passwords, etc use Self::hash and prove the password is safe instead
Available because is useful for testing or for provide a way to upgrade later to a strong password.
Sourcepub fn hash_argon(raw: &str, check: impl PasswordIsSafe) -> ResultPwd<Self>
pub fn hash_argon(raw: &str, check: impl PasswordIsSafe) -> ResultPwd<Self>
Hash a raw string into a PCH salted string using argon2::Argon2 and verify is safe using a checker
Sourcepub unsafe fn hash_argon_unsafe(raw: &str) -> ResultPwd<Self>
pub unsafe fn hash_argon_unsafe(raw: &str) -> ResultPwd<Self>
Hash a raw string into a PCH salted string using argon2::Argon2
§Safety
Check comment on Self::hash_unsafe
Sourcepub fn get_hash(&self) -> PasswordHash<'_>
pub fn get_hash(&self) -> PasswordHash<'_>
Return the constructed hash_unsafe from the internal String
§Safety
At this point the internal string is always a correct PHC in the defined PasswordAlgo
Sourcepub fn validate_password(&self, against: &str) -> Result<(), PasswordError>
pub fn validate_password(&self, against: &str) -> Result<(), PasswordError>
Check if this password match a raw &str
§Examples
use forbidden::prelude::*;
let p = unsafe{ Password::hash_unsafe("hi").unwrap() };
// Verify if the password match...
assert!(p.validate_password("hi").is_ok());
//Also can be used with equality in case you don't care for the error causes of not matching:
assert_eq!(p, "hi");Sourcepub fn salt() -> SaltString
pub fn salt() -> SaltString
A salted string that can be used for hashing passwords