From 0a1d125b04701fc92a8ca0672b1ca4e41e3c83df Mon Sep 17 00:00:00 2001 From: StNicolay Date: Tue, 27 Jun 2023 22:51:34 +0300 Subject: [PATCH] Improved the char counting in the check_master_pass function --- cryptography/src/passwords.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cryptography/src/passwords.rs b/cryptography/src/passwords.rs index a93fe1d..4ca55e2 100644 --- a/cryptography/src/passwords.rs +++ b/cryptography/src/passwords.rs @@ -58,12 +58,11 @@ pub fn generate_passwords( #[inline] pub fn check_master_pass(password: &str) -> bool { - if password.chars().count() < 8 { - return false; - } - + let mut count = 0; + let mut chars = password.chars(); let mut flags = PasswordFlags::empty(); - for char in password.chars() { + for char in &mut chars { + count += 1; if char.is_lowercase() { flags |= PasswordFlags::LOWERCASE } else if char.is_uppercase() { @@ -75,7 +74,8 @@ pub fn check_master_pass(password: &str) -> bool { } if flags.is_all() { - return true; + count += chars.count(); + return count >= 8; } } false