summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
authormrw1593 <botahamec@outlook.com>2023-03-19 13:23:20 -0400
committermrw1593 <botahamec@outlook.com>2023-05-29 10:45:26 -0400
commit8ec105595db9d2957c7327112e7a0b63d9d59400 (patch)
treea53e2e2c375d2d7155c30058a69dd713be4e5905 /src/models
parentf149374e2c6682ea5b9b1d692b001d6ab5faea4a (diff)
Create user
Diffstat (limited to 'src/models')
-rw-r--r--src/models/mod.rs3
-rw-r--r--src/models/user.rs44
2 files changed, 47 insertions, 0 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs
new file mode 100644
index 0000000..4a9be81
--- /dev/null
+++ b/src/models/mod.rs
@@ -0,0 +1,3 @@
+mod user;
+
+pub use user::User;
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()
+ }
+}