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);
// This also implements FromRequestParts (see `src/login/extract/login.rs`). As
// a result, it can be used as an extractor.
#[derive(Debug)]
pub struct Login {
pub id: Id,
pub name: String,
// 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