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, pub current_bal_id: Option, } 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 { #[sea_orm(has_many = "super::owner::Entity")] Owner, } impl Related for Entity { fn to() -> RelationDef { Relation::Owner.def() } } impl ActiveModelBehavior for ActiveModel {}