account: add hash_pwd_server()

This commit is contained in:
realaltffour 2020-08-03 18:56:10 +03:00
parent 366a37939b
commit 0559895031
No known key found for this signature in database
GPG Key ID: C1265D839D44DCB1
3 changed files with 28 additions and 5 deletions

View File

@ -7,7 +7,7 @@ use libtrader::db::cmd::get_company::get_company_from_db;
use libtrader::db::cmd::create_stock::create_stock;
use libtrader::ds::generic::company::Company;
use libtrader::ds::server::global_state::GlobalState;
use libtrader::account::hash_pwd::hash_pwd_client;
use libtrader::account::hash_pwd::{hash_pwd_client, hash_pwd_server};
use data_encoding::HEXUPPER;
@ -40,7 +40,12 @@ fn main() {
info!("state: {:?}\n", state);
let enc = hash_pwd_client("this is my real password").unwrap();
let mut enc = hash_pwd_client("this is my real password").unwrap();
println!("Hash: {}", HEXUPPER.encode(&enc.0));
println!("Salt: {}", HEXUPPER.encode(&enc.1));
enc = hash_pwd_server(HEXUPPER.encode(&enc.0).as_str()).unwrap();
println!("Hash: {}", HEXUPPER.encode(&enc.0));
println!("Salt: {}", HEXUPPER.encode(&enc.1));

View File

@ -3,7 +3,7 @@ use ring::{digest, pbkdf2, rand};
use std::num::NonZeroU32;
pub fn hash_pwd_client(pass: &str) ->
Result<([u8; digest::SHA512_OUTPUT_LEN], [u8;digest::SHA512_OUTPUT_LEN]), String> { // hash, salt
Result<([u8; digest::SHA512_OUTPUT_LEN], [u8;digest::SHA512_OUTPUT_LEN]), String> {
let client_iter: NonZeroU32 = NonZeroU32::new(100_000).unwrap();
let rng = rand::SystemRandom::new();
@ -22,6 +22,22 @@ Result<([u8; digest::SHA512_OUTPUT_LEN], [u8;digest::SHA512_OUTPUT_LEN]), String
Ok((hash, salt))
}
pub fn hash_pwd_server() -> Result<(), String> {
Ok(())
pub fn hash_pwd_server(hashed_pass: &str) ->
Result<([u8; digest::SHA512_OUTPUT_LEN], [u8;digest::SHA512_OUTPUT_LEN]), String> {
let client_iter: NonZeroU32 = NonZeroU32::new(200_000).unwrap();
let rng = rand::SystemRandom::new();
let mut salt = [0u8; digest::SHA512_OUTPUT_LEN];
rng.fill(&mut salt).unwrap();
let mut hash = [0u8; digest::SHA512_OUTPUT_LEN];
pbkdf2::derive(
pbkdf2::PBKDF2_HMAC_SHA512,
client_iter,
&salt,
hashed_pass.as_bytes(),
&mut hash);
Ok((hash, salt))
}

View File

@ -6,6 +6,8 @@ pub struct Account {
pub email: String,
pub is_pass: bool,
pub pass_hash: String,
pub pass_salt: String,
pub client_pass_salt: String,
pub portfolio: Portfolio,
pub transactions: Vec<f64>
}