fix: Generate correct bcrypt hash and update PostgreSQL admin password
- Create src/bin directory for temporary tools - Generate correct bcrypt hash (60 chars) for 'admin123' - Update PostgreSQL admins.password (clear corrupted data) - Reinitialize auth.sqlite with complete table structure - Verify admin login working with correct password Key fixes: - PostgreSQL admins.password: varchar(255) accepts 60-char bcrypt hash - auth.sqlite sftpgo_admins: correct password_hash synced - Admin login API: returns token + username - Token verify API: returns ok=true All tests passing: ✅ Admin sync: admins_synced=1 ✅ Hash length: 60 chars (bcrypt standard) ✅ Admin login: success ✅ Token verify: success Status: Admin authentication fully functional
This commit is contained in:
BIN
data/auth.sqlite
BIN
data/auth.sqlite
Binary file not shown.
6
src/bin/gen_hash.rs
Normal file
6
src/bin/gen_hash.rs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
@@ -1568,10 +1568,10 @@ async fn validate_config_handler() -> impl IntoResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn admin_login_handler(
|
async fn admin_login_handler(
|
||||||
State(state): State<crate::auth::AuthState>,
|
State(state): State<AppState>,
|
||||||
Json(body): Json<crate::auth::AdminLoginRequest>,
|
Json(body): Json<crate::auth::AdminLoginRequest>,
|
||||||
) -> impl IntoResponse {
|
) -> 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(),
|
Some(response) => (StatusCode::OK, Json(response)).into_response(),
|
||||||
None => (
|
None => (
|
||||||
StatusCode::UNAUTHORIZED,
|
StatusCode::UNAUTHORIZED,
|
||||||
@@ -1581,7 +1581,7 @@ async fn admin_login_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn admin_verify_handler(
|
async fn admin_verify_handler(
|
||||||
State(state): State<crate::auth::AuthState>,
|
State(state): State<AppState>,
|
||||||
headers: axum::http::HeaderMap,
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let auth_header = headers
|
let auth_header = headers
|
||||||
@@ -1590,7 +1590,7 @@ async fn admin_verify_handler(
|
|||||||
.and_then(|v| v.strip_prefix("Bearer "));
|
.and_then(|v| v.strip_prefix("Bearer "));
|
||||||
|
|
||||||
if let Some(token) = auth_header {
|
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 (
|
return (
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
Json(serde_json::json!({
|
Json(serde_json::json!({
|
||||||
|
|||||||
Reference in New Issue
Block a user