Struct firebase_scrypt::FirebaseScrypt
source · [−]pub struct FirebaseScrypt { /* private fields */ }
Expand description
Struct to simplify the usage of hash generation and checking.
Holds the salt separator, signer key, round and memory cost to make the usage of the hash generation and checking function easier.
Example
use firebase_scrypt::FirebaseScrypt;
const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;
let firebase_scrypt = FirebaseScrypt::new(SALT_SEPARATOR, SIGNER_KEY, ROUNDS, MEM_COST);
let password = "user1password";
let salt = "42xEC+ixf3L2lw==";
let password_hash ="lSrfV15cpx95/sZS2W9c9Kp6i/LVgQNDNC/qzrCnh1SAyZvqmZqAjTdn3aoItz+VHjoZilo78198JAdRuid5lQ==";
assert!(firebase_scrypt.verify_password(password, salt, password_hash).unwrap())
Implementations
sourceimpl FirebaseScrypt
impl FirebaseScrypt
sourcepub fn new(
salt_separator: &str,
signer_key: &str,
rounds: u32,
mem_cost: u32
) -> Self
pub fn new(
salt_separator: &str,
signer_key: &str,
rounds: u32,
mem_cost: u32
) -> Self
Create a new FirebaseScrypt
instance.
sourcepub fn verify_password(
&self,
password: &str,
salt: &str,
known_hash: &str
) -> Result<bool, GenerateHashError>
pub fn verify_password(
&self,
password: &str,
salt: &str,
known_hash: &str
) -> Result<bool, GenerateHashError>
Calls verify_password
with the data from the FirebaseScrypt
Example
use firebase_scrypt::FirebaseScrypt;
const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;
let password: &str = "user1password";
let salt: &str = "42xEC+ixf3L2lw==";
let password_hash: &str = "lSrfV15cpx95/sZS2W9c9Kp6i/LVgQNDNC/qzrCnh1SAyZvqmZqAjTdn3aoItz+VHjoZilo78198JAdRuid5lQ==";
let firebase_scrypt = FirebaseScrypt::new(SALT_SEPARATOR, SIGNER_KEY, ROUNDS, MEM_COST);
let is_valid = firebase_scrypt.verify_password(
password,
password_hash,
salt,
).unwrap();
assert!(is_valid)
sourcepub fn verify_password_bool(
&self,
password: &str,
salt: &str,
known_hash: &str
) -> bool
pub fn verify_password_bool(
&self,
password: &str,
salt: &str,
known_hash: &str
) -> bool
Calls FirebaseScrypt::verify_password
but returns false also if an error occurs, which
is usually the best thing to do.
sourcepub fn generate_base64_hash(
&self,
password: &str,
salt: &str
) -> Result<String, GenerateHashError>
pub fn generate_base64_hash(
&self,
password: &str,
salt: &str
) -> Result<String, GenerateHashError>
Generates a hash and returns its Base64 form, the same as the hashes from Firebase
Warning: Do not use this function to check if a given password is valid, because that could result in side-channel attacks.
Use the
FirebaseScrypt::verify_password
function instead.
Example
use firebase_scrypt::FirebaseScrypt;
const SALT_SEPARATOR: &str = "Bw==";
const SIGNER_KEY: &str = "jxspr8Ki0RYycVU8zykbdLGjFQ3McFUH0uiiTvC8pVMXAn210wjLNmdZJzxUECKbm0QsEmYUSDzZvpjeJ9WmXA==";
const ROUNDS: u32 = 8;
const MEM_COST: u32 = 14;
let password = "user1password";
let salt = "42xEC+ixf3L2lw==";
let firebase_scrypt = FirebaseScrypt::new(SALT_SEPARATOR, SIGNER_KEY, ROUNDS, MEM_COST);
firebase_scrypt.generate_base64_hash(password, salt).unwrap();
Trait Implementations
sourceimpl Clone for FirebaseScrypt
impl Clone for FirebaseScrypt
sourcefn clone(&self) -> FirebaseScrypt
fn clone(&self) -> FirebaseScrypt
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for FirebaseScrypt
impl Debug for FirebaseScrypt
sourceimpl Ord for FirebaseScrypt
impl Ord for FirebaseScrypt
sourcefn cmp(&self, other: &FirebaseScrypt) -> Ordering
fn cmp(&self, other: &FirebaseScrypt) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<FirebaseScrypt> for FirebaseScrypt
impl PartialEq<FirebaseScrypt> for FirebaseScrypt
sourcefn eq(&self, other: &FirebaseScrypt) -> bool
fn eq(&self, other: &FirebaseScrypt) -> bool
sourceimpl PartialOrd<FirebaseScrypt> for FirebaseScrypt
impl PartialOrd<FirebaseScrypt> for FirebaseScrypt
sourcefn partial_cmp(&self, other: &FirebaseScrypt) -> Option<Ordering>
fn partial_cmp(&self, other: &FirebaseScrypt) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for FirebaseScrypt
impl StructuralEq for FirebaseScrypt
impl StructuralPartialEq for FirebaseScrypt
Auto Trait Implementations
impl RefUnwindSafe for FirebaseScrypt
impl Send for FirebaseScrypt
impl Sync for FirebaseScrypt
impl Unpin for FirebaseScrypt
impl UnwindSafe for FirebaseScrypt
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more