MCPcopy Index your code
hub / github.com/endbasic/endbasic / validate_password_complexity

Function validate_password_complexity

client/src/cmds.rs:417–437  ·  view source on GitHub ↗

Checks if a password is sufficiently complex and returns an error when it isn't.

(password: &str)

Source from the content-addressed store, hash-verified

415
416/// Checks if a password is sufficiently complex and returns an error when it isn't.
417fn validate_password_complexity(password: &str) -> Result<(), &'static str> {
418 if password.len() < 8 {
419 return Err("Must be at least 8 characters long");
420 }
421
422 let mut alphabetic = false;
423 let mut numeric = false;
424 for ch in password.chars() {
425 if ch.is_alphabetic() {
426 alphabetic = true;
427 } else if ch.is_numeric() {
428 numeric = true;
429 }
430 }
431
432 if !alphabetic || !numeric {
433 return Err("Must contain letters and numbers");
434 }
435
436 Ok(())
437}
438
439/// The `SIGNUP` command.
440pub struct SignupCommand {

Calls 2

charsMethod · 0.80
lenMethod · 0.45