diff --git a/data/auth.sqlite b/data/auth.sqlite index 4fe6553..884735c 100644 Binary files a/data/auth.sqlite and b/data/auth.sqlite differ diff --git a/src/bin/gen_hash.rs b/src/bin/gen_hash.rs new file mode 100644 index 0000000..10ef430 --- /dev/null +++ b/src/bin/gen_hash.rs @@ -0,0 +1,6 @@ +fn main() { + use bcrypt::{hash, DEFAULT_COST}; + let password = std::env::args().nth(1).unwrap_or("admin123".to_string()); + let hashed = hash(&password, DEFAULT_COST).unwrap(); + println!("{}", hashed); +} diff --git a/src/server.rs b/src/server.rs index 415aad3..6fdb4a4 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1568,10 +1568,10 @@ async fn validate_config_handler() -> impl IntoResponse { } async fn admin_login_handler( - State(state): State, + State(state): State, Json(body): Json, ) -> impl IntoResponse { - match state.admin_login(&body.username, &body.password) { + match state.auth.admin_login(&body.username, &body.password) { Some(response) => (StatusCode::OK, Json(response)).into_response(), None => ( StatusCode::UNAUTHORIZED, @@ -1581,7 +1581,7 @@ async fn admin_login_handler( } async fn admin_verify_handler( - State(state): State, + State(state): State, headers: axum::http::HeaderMap, ) -> impl IntoResponse { let auth_header = headers @@ -1590,7 +1590,7 @@ async fn admin_verify_handler( .and_then(|v| v.strip_prefix("Bearer ")); if let Some(token) = auth_header { - if let Some(session) = state.verify_admin_token(token) { + if let Some(session) = state.auth.verify_admin_token(token) { return ( StatusCode::OK, Json(serde_json::json!({