1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Pass the rng and clock around

This commit is contained in:
Quentin Gliech
2022-10-21 18:50:06 +02:00
parent 5c7e66a9b2
commit 559181c2c3
40 changed files with 504 additions and 218 deletions

View File

@ -6,23 +6,25 @@ edition = "2021"
license = "Apache-2.0"
[dependencies]
axum = "0.6.0-rc.2"
tokio = { version = "1.21.2", features = ["full"] }
futures-util = "0.3.25"
anyhow = "1.0.66"
argon2 = { version = "0.4.1", features = ["password-hash"] }
atty = "0.2.14"
axum = "0.6.0-rc.2"
clap = { version = "4.0.18", features = ["derive"] }
dotenv = "0.15.0"
tower = { version = "0.4.13", features = ["full"] }
futures-util = "0.3.25"
hyper = { version = "0.14.22", features = ["full"] }
serde_yaml = "0.9.14"
serde_json = "1.0.87"
url = "2.3.1"
argon2 = { version = "0.4.1", features = ["password-hash"] }
watchman_client = "0.8.0"
atty = "0.2.14"
listenfd = "1.0.0"
rustls = "0.20.7"
itertools = "0.10.5"
listenfd = "1.0.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
rustls = "0.20.7"
serde_json = "1.0.87"
serde_yaml = "0.9.14"
tokio = { version = "1.21.2", features = ["full"] }
tower = { version = "0.4.13", features = ["full"] }
url = "2.3.1"
watchman_client = "0.8.0"
tracing = "0.1.37"
tracing-appender = "0.2.2"

View File

@ -20,7 +20,9 @@ use mas_storage::{
user::{
lookup_user_by_username, lookup_user_email, mark_user_email_as_verified, register_user,
},
Clock,
};
use rand::SeedableRng;
use tracing::{info, warn};
#[derive(Parser, Debug)]
@ -51,14 +53,17 @@ enum Subcommand {
impl Options {
pub async fn run(&self, root: &super::Options) -> anyhow::Result<()> {
use Subcommand as SC;
let clock = Clock::default();
match &self.subcommand {
SC::Register { username, password } => {
let config: DatabaseConfig = root.load_config()?;
let pool = config.connect().await?;
let mut txn = pool.begin().await?;
let hasher = Argon2::default();
let rng = rand_chacha::ChaChaRng::from_entropy();
let user = register_user(&mut txn, hasher, username, password).await?;
let user = register_user(&mut txn, rng, &clock, hasher, username, password).await?;
txn.commit().await?;
info!(?user, "User registered");
@ -76,7 +81,7 @@ impl Options {
let user = lookup_user_by_username(&mut txn, username).await?;
let email = lookup_user_email(&mut txn, &user, email).await?;
let email = mark_user_email_as_verified(&mut txn, email).await?;
let email = mark_user_email_as_verified(&mut txn, &clock, email).await?;
txn.commit().await?;
info!(?email, "Email marked as verified");