Skip to content

Commit

Permalink
Password validation Changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Debajyoti14 committed May 14, 2024
1 parent 9a7d3eb commit be37426
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/handlers/user_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 28 additions & 9 deletions src/utils/validation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit be37426

Please sign in to comment.