feat: authentication system
This commit is contained in:
parent
d8c29e1ec8
commit
37153c6e36
15 changed files with 852 additions and 18 deletions
26
src/entities/user.rs
Normal file
26
src/entities/user.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "User")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = true)]
|
||||
pub id: u32,
|
||||
#[sea_orm(unique)]
|
||||
pub username: String,
|
||||
pub hashed_password: String,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn verify_password(&self, password: String) -> bool {
|
||||
let parsed_hash = PasswordHash::new(&self.hashed_password).unwrap();
|
||||
Argon2::default().verify_password(password.as_bytes(), &parsed_hash).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in a new issue