use bcrypt::hash; use bcrypt::verify; use bcrypt::DEFAULT_COST; use crate::Privacy; use crate::Result; #[derive(sqlx::FromRow)] pub struct User { pub username: String, pub password: String, pub email: Option, pub bio: Option, pub site: Option, pub privacy: Privacy, pub admin: bool, } impl User { pub fn new(username: String, password: String) -> Result { let password_hash = hash(password, DEFAULT_COST)?; Ok(Self { username, password: password_hash, email: None, bio: None, site: None, privacy: Privacy::Public, admin: true, }) } pub fn verify_password(&self, password: &str) -> Result { Ok(verify(password, &self.password)?) } }