From 8ec105595db9d2957c7327112e7a0b63d9d59400 Mon Sep 17 00:00:00 2001 From: mrw1593 Date: Sun, 19 Mar 2023 13:23:20 -0400 Subject: Create user --- src/models/user.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/models/user.rs (limited to 'src/models/user.rs') diff --git a/src/models/user.rs b/src/models/user.rs new file mode 100644 index 0000000..f5fd20e --- /dev/null +++ b/src/models/user.rs @@ -0,0 +1,44 @@ +use std::hash::Hash; + +use uuid::Uuid; + +use crate::services::crypto::PasswordHash; + +#[derive(Debug, Clone)] +pub struct User { + pub user_id: Uuid, + pub username: Box, + pub password: PasswordHash, +} + +impl PartialEq for User { + fn eq(&self, other: &Self) -> bool { + self.user_id == other.user_id + } +} + +impl Eq for User {} + +impl Hash for User { + fn hash(&self, state: &mut H) { + state.write_u128(self.user_id.as_u128()) + } +} + +impl User { + pub fn username(&self) -> &str { + &self.username + } + + pub fn password_hash(&self) -> &[u8] { + self.password.hash() + } + + pub fn password_salt(&self) -> &[u8] { + self.password.salt() + } + + pub fn password_version(&self) -> u8 { + self.password.version() + } +} -- cgit v1.2.3