feat: DB operations can fail

This commit is contained in:
selfhoster selfhoster 2026-09-01 23:27:02 +02:00
commit 7527ba7a09
6 changed files with 50 additions and 19 deletions

View file

@ -2,6 +2,7 @@ use tokio::sync::RwLock;
use std::sync::Arc;
use crate::db::error::BoxedError;
use crate::db::{DatabaseInterface, UserRef};
#[derive(Clone, Debug)]
@ -26,13 +27,13 @@ impl<D: DatabaseInterface> Database<D> {
/// TODO: we may want to make sure the method runs in constant time
/// to avoid leaking information about existing users...
/// or maybe we do not care.
pub async fn check_password(&self, user: &UserRef, password: &str) -> bool {
let Some(user) = self.get_user(user).await else {
pub async fn check_password(&self, user: &UserRef, password: &str) -> Result<bool, BoxedError> {
let Some(user) = self.get_user(user).await? else {
tracing::debug!("check_password: User not found {user}");
return false;
return Ok(false);
};
tracing::debug!("Comparing {} and {}", user.password, password);
user.password == password
Ok(user.password == password)
}
}