Skip to content

Commit 643aa7a

Browse files
committed
fix: errors in axum-social-with-tests
1 parent 828d68e commit 643aa7a

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

examples/postgres/axum-social-with-tests/src/http/user.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use axum::extract::State;
22
use axum::http::StatusCode;
33
use axum::{routing::post, Json, Router};
4-
use rand::Rng;
54
use regex::Regex;
65
use std::{sync::LazyLock, time::Duration};
76

@@ -85,7 +84,7 @@ impl UserAuth {
8584

8685
// Sleep a random amount of time to avoid leaking existence of a user in timing.
8786
let sleep_duration =
88-
rand::thread_rng().gen_range(Duration::from_millis(100)..=Duration::from_millis(500));
87+
rand::random_range(Duration::from_millis(100)..=Duration::from_millis(500));
8988
tokio::time::sleep(sleep_duration).await;
9089

9190
Err(Error::UnprocessableEntity(

examples/postgres/axum-social-with-tests/src/password.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use anyhow::{anyhow, Context};
22
use tokio::task;
33

4-
use argon2::password_hash::SaltString;
54
use argon2::{password_hash, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
65

76
pub async fn hash(password: String) -> anyhow::Result<String> {
87
task::spawn_blocking(move || {
9-
let salt = SaltString::generate(rand::thread_rng());
108
Ok(Argon2::default()
11-
.hash_password(password.as_bytes(), &salt)
9+
.hash_password(password.as_bytes())
1210
.map_err(|e| anyhow!(e).context("failed to hash password"))?
1311
.to_string())
1412
})
@@ -25,7 +23,7 @@ pub async fn verify(password: String, hash: String) -> anyhow::Result<bool> {
2523

2624
match res {
2725
Ok(()) => Ok(true),
28-
Err(password_hash::Error::Password) => Ok(false),
26+
Err(password_hash::Error::PasswordInvalid) => Ok(false),
2927
Err(e) => Err(anyhow!(e).context("failed to verify password")),
3028
}
3129
})

0 commit comments

Comments
 (0)