feat: Start dummy in-memory database
This commit is contained in:
parent
1ef02c58dd
commit
bdb5008914
9 changed files with 181 additions and 3 deletions
36
src/db/common.rs
Normal file
36
src/db/common.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use tokio::sync::RwLock;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::db::{DatabaseInterface, UserRef};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Database<D: DatabaseInterface> {
|
||||
pub inner: Arc<RwLock<D>>,
|
||||
}
|
||||
|
||||
impl<D: DatabaseInterface> Database<D> {
|
||||
pub fn new(db: D) -> Self {
|
||||
Self {
|
||||
inner: Arc::new(RwLock::new(db)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DatabaseInterface> Database<D> {
|
||||
/// Return false if the user doesn't exist, or the password is wrong.
|
||||
///
|
||||
/// TODO: should we return something else when the account doesn't exist?
|
||||
/// or is it a feature to behave in the same way?
|
||||
///
|
||||
/// 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.
|
||||
async fn check_password(&self, user: &UserRef, password: &str) -> bool {
|
||||
let Some(user) = self.get_user(user).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
user.password == password
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue