PaperTrader/src/libtrader/server/account/hash_pwd.rs

26 lines
930 B
Rust
Raw Normal View History

use crate::common::account::hash::*;
use crate::common::account::salt::*;
2020-08-11 10:16:25 +00:00
/// Generates a storable server password hash from a client hashed password.
2021-05-19 14:51:36 +00:00
///
2020-08-11 10:16:25 +00:00
/// 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:
2021-05-19 14:51:36 +00:00
/// hashed_pass - The client hashed password sent to the server.
2020-08-11 10:16:25 +00:00
///
/// 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);
2020-08-14 08:06:46 +00:00
(hash, salt)
2020-08-11 10:16:25 +00:00
}