Skip to content

Commit

Permalink
Password validation Changed (#36)
Browse files Browse the repository at this point in the history
* Password validation Changed

* Add Special Character support for password
  • Loading branch information
Debajyoti14 authored May 14, 2024
1 parent 7b32df1 commit a263183
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
File renamed without changes.
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
45 changes: 35 additions & 10 deletions src/utils/validation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,42 @@ impl Validation {
}

pub fn password(password: &str) -> bool {
let mut has_alpha = false;
let mut has_digit = false;

for c in password.chars() {
if c.is_ascii_alphabetic() {
has_alpha = true;
} else if c.is_ascii_digit() {
has_digit = true;
}
// Minimum length requirement
let min_length = 8;
if password.len() < min_length {
return false;
}

has_alpha && has_digit && password.len() >= 8
// 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;
}

// 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;
}

// Password is valid
return true;
}
}

0 comments on commit a263183

Please sign in to comment.