password-hash-self-service/src/lib.rs

28 lines
673 B
Rust

use pwhash::{
bcrypt::{self, BcryptSetup},
sha512_crypt, HashSetup,
};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn hash_bcrypt(password: &str, cost: u32) -> JsValue {
let setup = BcryptSetup {
cost: Some(cost),
..Default::default()
};
bcrypt::hash_with(setup, password)
.expect("failed to calculate bcrypt hash")
.into()
}
#[wasm_bindgen]
pub fn hash_sha512crypt(password: &str, rounds: u32) -> JsValue {
let setup = HashSetup {
rounds: Some(rounds),
salt: None,
};
sha512_crypt::hash_with(setup, password)
.expect("failed to calculate sha512-crypt hash")
.into()
}