From: Nutomic Date: Sat, 5 Nov 2022 00:56:38 +0000 (+0000) Subject: Fix password length check (#2536) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/hacktivis.me/readmes/README.ja.md?a=commitdiff_plain;h=50a2233b526426357c8e31509010f7fcb5ffbf3f;p=lemmy.git Fix password length check (#2536) --- diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index 6b0b011a..8c341c44 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -314,7 +314,7 @@ pub async fn build_federated_instances( /// Checks the password length pub fn password_length_check(pass: &str) -> Result<(), LemmyError> { - if !(10..=60).contains(&pass.len()) { + if !(10..=60).contains(&pass.chars().count()) { Err(LemmyError::from_message("invalid_password")) } else { Ok(()) @@ -791,3 +791,17 @@ pub fn listing_type_with_site_default( &local_site.default_post_listing_type, )?)) } + +#[cfg(test)] +mod tests { + use crate::utils::password_length_check; + + #[test] + #[rustfmt::skip] + fn password_length() { + assert!(password_length_check("Õ¼¾°3yË,o¸ãtÌÈú|ÇÁÙAøüÒI©·¤(T]/ð>æºWæ[C¤bªWöaÃÎñ·{=û³&§½K/c").is_ok()); + assert!(password_length_check("1234567890").is_ok()); + assert!(password_length_check("short").is_err()); + assert!(password_length_check("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong").is_err()); + } +}