mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 14:45:10 +00:00
Fix password length check (#2536)
This commit is contained in:
parent
2207fed0f5
commit
50a2233b52
|
@ -314,7 +314,7 @@ pub async fn build_federated_instances(
|
||||||
|
|
||||||
/// Checks the password length
|
/// Checks the password length
|
||||||
pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
|
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"))
|
Err(LemmyError::from_message("invalid_password"))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -791,3 +791,17 @@ pub fn listing_type_with_site_default(
|
||||||
&local_site.default_post_listing_type,
|
&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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue