move user stuff to module

This commit is contained in:
Joe Ardent 2023-05-12 14:24:57 -07:00
parent 772f1471ba
commit 0223242473
2 changed files with 32 additions and 30 deletions

View file

@ -1,35 +1,6 @@
#[macro_use] #[macro_use]
extern crate justerror; extern crate justerror;
use argon2::{
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
Argon2,
};
use uuid::Uuid;
pub mod db; pub mod db;
pub mod handlers; pub mod handlers;
pub mod users;
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,
}

31
src/users.rs Normal file
View 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,
}