From be374261dd08af771532e34e616ea363375e6b62 Mon Sep 17 00:00:00 2001 From: Debajyoti14 Date: Tue, 14 May 2024 12:48:36 +0530 Subject: [PATCH 1/2] Password validation Changed --- src/handlers/user_handler.rs | 2 -- src/utils/validation_utils.rs | 37 ++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/handlers/user_handler.rs b/src/handlers/user_handler.rs index b55aec6..5ef3cfb 100644 --- a/src/handlers/user_handler.rs +++ b/src/handlers/user_handler.rs @@ -51,8 +51,6 @@ pub async fn update_user_handler( Err(e) => return Err(e), }; - // let kek = env::var("SERVER_KEK").expect("Server Kek must be set."); - println!(">> DEK DATA Decrypted: {:?}", dek_data); // find the user in the users collection using the uid diff --git a/src/utils/validation_utils.rs b/src/utils/validation_utils.rs index 2bd4f2f..bf69c4f 100644 --- a/src/utils/validation_utils.rs +++ b/src/utils/validation_utils.rs @@ -8,17 +8,36 @@ impl Validation { } pub fn password(password: &str) -> bool { - let mut has_alpha = false; - let mut has_digit = false; + // Minimum length requirement + let min_length = 8; + if password.len() < min_length { + return false; + } + + // Check for at least one lowercase letter + let has_lowercase = password.chars().any(|c| c.is_lowercase()); + if !has_lowercase { + return false; + } + + // Check for at least one uppercase letter + let has_uppercase = password.chars().any(|c| c.is_uppercase()); + if !has_uppercase { + return false; + } + + // Check for at least one number + let has_number = password.chars().any(|c| c.is_numeric()); + if !has_number { + return false; + } - for c in password.chars() { - if c.is_ascii_alphabetic() { - has_alpha = true; - } else if c.is_ascii_digit() { - has_digit = true; - } + // No whitespace allowed + if password.contains(' ') { + return false; } - has_alpha && has_digit && password.len() >= 8 + // Password is valid + return true; } } From d5e3eb40067c6ada4cb1a4e6dadecf927b9b7f3b Mon Sep 17 00:00:00 2001 From: Debajyoti14 Date: Tue, 14 May 2024 13:19:37 +0530 Subject: [PATCH 2/2] Add Special Character support for password --- openapi.yaml => docs/api-docs/openapi.yaml | 0 src/utils/validation_utils.rs | 6 ++++++ 2 files changed, 6 insertions(+) rename openapi.yaml => docs/api-docs/openapi.yaml (100%) diff --git a/openapi.yaml b/docs/api-docs/openapi.yaml similarity index 100% rename from openapi.yaml rename to docs/api-docs/openapi.yaml diff --git a/src/utils/validation_utils.rs b/src/utils/validation_utils.rs index bf69c4f..900214b 100644 --- a/src/utils/validation_utils.rs +++ b/src/utils/validation_utils.rs @@ -32,6 +32,12 @@ impl Validation { return false; } + // Check for at least one special character + let has_special = password.chars().any(|c| c.is_ascii_punctuation()); + if !has_special { + return false; + } + // No whitespace allowed if password.contains(' ') { return false;