completed implementation of validation function
This commit is contained in:
+36
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user