Checks if a password is sufficiently complex and returns an error when it isn't.
(password: &str)
| 415 | |
| 416 | /// Checks if a password is sufficiently complex and returns an error when it isn't. |
| 417 | fn 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. |
| 440 | pub struct SignupCommand { |