Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/server/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@
.to_string()
}

pub fn verify_password(password: &str, hash: &str) -> bool {

Check warning on line 93 in crates/server/src/auth.rs

View workflow job for this annotation

GitHub Actions / Check

function `verify_password` is never used

Check warning on line 93 in crates/server/src/auth.rs

View workflow job for this annotation

GitHub Actions / Clippy

function `verify_password` is never used
use argon2::{PasswordHash, PasswordVerifier};

let parsed_hash = PasswordHash::new(hash).expect("Invalid hash format");
let Ok(parsed_hash) = PasswordHash::new(hash) else {
return false;
};

Argon2::default()
.verify_password(password.as_bytes(), &parsed_hash)
.is_ok()
Expand Down Expand Up @@ -170,6 +173,12 @@
assert!(!verify_password(empty_password, &hashed));
}

#[test]
fn test_verify_password_invalid_hash() {
// Invalid hash input should not panic and should return false.
assert!(!verify_password("test_password", "not-a-valid-hash"));
}

#[test]
fn test_auth_error_display() {
let missing_creds = AuthError::MissingCredentials;
Expand Down
Loading