Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password validation Changed #36

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}