diff options
| author | mrw1593 <botahamec@outlook.com> | 2023-03-19 13:23:20 -0400 |
|---|---|---|
| committer | mrw1593 <botahamec@outlook.com> | 2023-05-29 10:45:26 -0400 |
| commit | 8ec105595db9d2957c7327112e7a0b63d9d59400 (patch) | |
| tree | a53e2e2c375d2d7155c30058a69dd713be4e5905 /src/models/user.rs | |
| parent | f149374e2c6682ea5b9b1d692b001d6ab5faea4a (diff) | |
Create user
Diffstat (limited to 'src/models/user.rs')
| -rw-r--r-- | src/models/user.rs | 44 |
1 files changed, 44 insertions, 0 deletions
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<str>, + 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<H: std::hash::Hasher>(&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() + } +} |
