Sign up method.
beginning of adding methods to create account and authentication.
This commit is contained in:
parent
855eb16973
commit
5e4e086247
5 changed files with 258 additions and 32 deletions
16
backend/src/hash.rs
Normal file
16
backend/src/hash.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use std::{string::String, env::consts::OS};
|
||||
|
||||
use argon2::{
|
||||
password_hash::{
|
||||
Error,
|
||||
rand_core::OsRng,
|
||||
PasswordHash, PasswordHasher, PasswordVerifier, SaltString
|
||||
},
|
||||
Argon2
|
||||
};
|
||||
|
||||
pub fn hash(password: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
let argon2 = Argon2::default();
|
||||
argon2.hash_password(password.as_bytes(), &salt).map(|h| h.to_string()).map_err(|e| e.into())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue