move user stuff to module
This commit is contained in:
parent
772f1471ba
commit
0223242473
2 changed files with 32 additions and 30 deletions
31
src/lib.rs
31
src/lib.rs
|
@ -1,35 +1,6 @@
|
|||
#[macro_use]
|
||||
extern crate justerror;
|
||||
|
||||
use argon2::{
|
||||
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
Argon2,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub mod db;
|
||||
pub mod handlers;
|
||||
|
||||
fn create_user(username: &str, password: &[u8]) -> Result<Uuid, CreateUserError> {
|
||||
// Argon2 with default params (Argon2id v19)
|
||||
let argon2 = Argon2::default();
|
||||
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
let password_hash = argon2
|
||||
.hash_password(password, &salt)
|
||||
.unwrap() // safe to unwrap, we know the salt is valid
|
||||
.to_string();
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[Error(desc = "Could not create user.")]
|
||||
#[non_exhaustive]
|
||||
pub struct CreateUserError(#[from] CreateUserErrorKind);
|
||||
|
||||
#[Error]
|
||||
#[non_exhaustive]
|
||||
pub enum CreateUserErrorKind {
|
||||
AlreadyExists,
|
||||
Unknown,
|
||||
}
|
||||
pub mod users;
|
||||
|
|
31
src/users.rs
Normal file
31
src/users.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use argon2::{
|
||||
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
Argon2,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
fn create_user(username: &str, password: &[u8]) -> Result<Uuid, CreateUserError> {
|
||||
// Argon2 with default params (Argon2id v19)
|
||||
let argon2 = Argon2::default();
|
||||
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
let password_hash = argon2
|
||||
.hash_password(password, &salt)
|
||||
.unwrap() // safe to unwrap, we know the salt is valid
|
||||
.to_string();
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[Error(desc = "Could not create user.")]
|
||||
#[non_exhaustive]
|
||||
pub struct CreateUserError(#[from] CreateUserErrorKind);
|
||||
|
||||
#[Error]
|
||||
#[non_exhaustive]
|
||||
pub enum CreateUserErrorKind {
|
||||
AlreadyExists,
|
||||
PasswordMismatch,
|
||||
MissingFields,
|
||||
Unknown,
|
||||
}
|
Loading…
Reference in a new issue