26 lines
930 B
Rust
26 lines
930 B
Rust
use crate::common::account::hash::*;
|
|
use crate::common::account::salt::*;
|
|
|
|
/// Generates a storable server password hash from a client hashed password.
|
|
///
|
|
/// Takes in a client hashed password, outputs a storable new hash. The returned result is 'safe'
|
|
/// to be stored on the server side. The salt returned is for the hashed version of the hashed
|
|
/// client password.
|
|
///
|
|
/// Arguments:
|
|
/// hashed_pass - The client hashed password sent to the server.
|
|
///
|
|
/// Returns: a tuple containing the final hash and the hash's salt, nothing on failure.
|
|
///
|
|
/// Example:
|
|
/// ```rust
|
|
/// let enc = hash_pwd("THISISTOTALLYAHASHEDTHING...").unwrap();
|
|
/// println!("Server Hash: {}", HEXUPPER.encode(&enc.0));
|
|
/// println!("Server Salt: {}", HEXUPPER.encode(&enc.1));
|
|
/// ```
|
|
pub fn hash_pwd(hashed_pass: &str) -> (String, String) {
|
|
let salt = gen_salt();
|
|
let hash = hash(&hashed_pass, &salt, 500_000);
|
|
(hash, salt)
|
|
}
|