use argon2::Argon2;
use password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString};
use rand_core::OsRng;
use sqlx::{sqlite::Sqlite, SqliteConnection, Transaction};
use crate::error::BoxedError;
use crate::id::Id as BaseId;
pub trait Provider {
fn logins(&mut self) -> Logins;
}
impl<'c> Provider for Transaction<'c, Sqlite> {
fn logins(&mut self) -> Logins {
Logins(self)
}
}
pub struct Logins<'t>(&'t mut SqliteConnection);
#[derive(Debug)]
pub struct Login {
pub id: Id,
// Field unused (as of this writing), omitted to avoid warnings.
// Feel free to add it:
//
// pub name: String,
// However, the omission of the hashed password is deliberate, to minimize
// the chance that it ends up tangled up in debug output or in some other
// chunk of logic elsewhere.
}
impl<'c> Logins<'c> {
/// Create a new login, if the name is not already taken. Returns a [Login]
/// if a new login has actually been created, or `None` if an existing login
/// was found.
pub async fn create(
&mut self,
name: &str,
password: &str,
) -> Result