use color_eyre::Result; use serde::{Deserialize, Serialize}; use sqlx::SqlitePool; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct User { pub id: i64, pub name: String, /// I hate this. It's stored in plaintext. Why? password: String, pub is_admin: bool, } impl User { pub fn verify(&self, hashed_password: &str, salt: &str) -> bool { let ours = md5::compute(format!("{}{}", self.password, salt)); let ours = format!("{ours:x}"); ours == hashed_password } } pub async fn get_user(pool: &SqlitePool, name: &str) -> Result> { Ok( sqlx::query_as!(User, "SELECT * FROM users WHERE name = ?", name) .fetch_optional(pool) .await?, ) }