use rusqlite::Connection; pub fn init_db() -> Connection { let conn = Connection::open("server.db").unwrap(); conn.execute( "CREATE TABLE IF NOT EXISTS users ( username TEXT PRIMARY KEY, hashed_password TEXT NOT NULL )", [], ).unwrap(); conn } pub fn add_user(conn: &Connection, username: &str, hashed_password: &str) -> Result<(), Box> { conn.execute( "INSERT INTO users (username, hashed_password) VALUES (?1, ?2)", [username, hashed_password], )?; Ok(()) } pub fn get_hashed_password(conn: &Connection, username: &str) -> Option { let mut stmt = conn.prepare("SELECT hashed_password FROM users WHERE username = ?1").unwrap(); let mut rows = stmt.query([username]).unwrap(); if let Ok(Some(row)) = rows.next() { row.get(0).ok() } else { None } }