diff --git a/Cargo.lock b/Cargo.lock index 286f085..9cf127a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1586,6 +1586,7 @@ dependencies = [ "tower-http", "tracing", "tracing-subscriber", + "unicode-normalization", "url", "uuid", ] diff --git a/Cargo.toml b/Cargo.toml index b7a8910..c1b9a69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,6 @@ tokio = { version = "1.29.1", features = ["full"] } tower-http = { version = "0.4.4", features = ["cors"] } tracing = "0.1.37" tracing-subscriber = "0.3.17" +unicode-normalization = "0.1.22" url = "2.4.0" uuid = { version = "1.4.0", features = ["serde", "v4"] } diff --git a/src/app/authentication.rs b/src/app/authentication.rs index 4b802b5..1943bac 100644 --- a/src/app/authentication.rs +++ b/src/app/authentication.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use tracing::*; pub async fn api_gen_passtoken(token_info: Basic, conn: Arc>) -> ReturnData { - info!("Try gen passtoken"); + info!("Try gen passtoken: {}", token_info.username()); let res = gen_passtoken(token_info, conn).await; result_to_handler_with_log( |_| Some("Success gen passtoken".to_string()), diff --git a/src/authentication.rs b/src/authentication.rs index 9b15c9c..ff14446 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -6,6 +6,7 @@ use rand::{ }; use serde::{Deserialize, Serialize}; use std::env; +use unicode_normalization::UnicodeNormalization; use uuid::Uuid; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, sqlx::FromRow)] @@ -107,7 +108,7 @@ pub fn gen_passtoken(role: Role, key: &str) -> Result { .map_err(|_| QrError::Environment("ADMINISTRATOR_LIMIT_DAYS".to_string()))? .parse::() .map_err(|_| QrError::Environment("ADMINISTRATOR_LIMIT_DAYS".to_string()))?; - if key == pass { + if key.nfc().collect::() == pass.nfc().collect::() { Ok(Passtoken::new(role, limit_days)) } else { Err(QrError::Authorized) @@ -120,7 +121,7 @@ pub fn gen_passtoken(role: Role, key: &str) -> Result { .map_err(|_| QrError::Environment("EQUIPMENT_MANAGER_LIMIT_DAYS".to_string()))? .parse::() .map_err(|_| QrError::Environment("EQUIPMENT_MANAGER_LIMIT_DAYS".to_string()))?; - if key == pass { + if key.nfc().collect::() == pass.nfc().collect::() { Ok(Passtoken::new(role, limit_days)) } else { Err(QrError::Authorized) @@ -133,7 +134,7 @@ pub fn gen_passtoken(role: Role, key: &str) -> Result { .map_err(|_| QrError::Environment("GENERAL_LIMIT_DAYS".to_string()))? .parse::() .map_err(|_| QrError::Environment("GENERAL_LIMIT_DAYS".to_string()))?; - if key == pass { + if key.nfc().collect::() == pass.nfc().collect::() { Ok(Passtoken::new(role, limit_days)) } else { Err(QrError::Authorized)