diff --git a/src/main.rs b/src/main.rs index a495463..df06cad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,6 +44,42 @@ fn validate_password(password: &str, policy: &PasswordPolicy) -> bool { return false; } } + if policy.0.charset.contains(CharSet::LOWERCASE) { + let mut found_lower = false; + for c in password.chars() { + if LOWERCASE_CHARS.contains(&(c as u8)) { + found_lower = true; + break; + } + } + if !found_lower { + return false; + } + } + if policy.0.charset.contains(CharSet::NUMBERS) { + let mut found_number = false; + for c in password.chars() { + if NUMBER_CHARS.contains(&(c as u8)) { + found_number = true; + break; + } + } + if !found_number { + return false; + } + } + if policy.0.charset.contains(CharSet::SYMBOLS) { + let mut found_symbol = false; + for c in password.chars() { + if SYMBOL_CHARS.contains(&(c as u8)) { + found_symbol = true; + break; + } + } + if !found_symbol { + return false; + } + } // todo: do similar checks here true }