diff --git a/crates/izlek-core/src/auth.rs b/crates/izlek-core/src/auth.rs index 1a486d9..7abe465 100644 --- a/crates/izlek-core/src/auth.rs +++ b/crates/izlek-core/src/auth.rs @@ -25,6 +25,13 @@ pub const ARGON2_PARALLELISM: u32 = 1; /// How many bytes of randomness every token carries. pub const TOKEN_BYTES: usize = 16; +/// The shortest password this app accepts. +/// +/// Named because the form that takes a new password carries it too — as +/// `minlength`, so the browser enforces the rule where it is being broken +/// rather than the server explaining it afterwards. Two places, one number. +pub const MIN_PASSWORD_CHARS: usize = 10; + /// A password rule the person's choice broke. The wording is the wording on the /// first-sign-in screen. #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] @@ -155,7 +162,7 @@ pub fn check_password( ) -> Result<(), PasswordProblem> { // Counted in characters, not bytes: a ten-character password is ten // characters whatever alphabet it is in. - if password.chars().count() < 10 { + if password.chars().count() < MIN_PASSWORD_CHARS { return Err(PasswordProblem::TooShort); } diff --git a/crates/izlek-web/src/pages.rs b/crates/izlek-web/src/pages.rs index 65b3db7..8fc4344 100644 --- a/crates/izlek-web/src/pages.rs +++ b/crates/izlek-web/src/pages.rs @@ -117,6 +117,7 @@ async fn setup_card(cx: &Cx) -> Result { type="password" name="password" autocomplete="new-password" + minlength=(izlek_core::auth::MIN_PASSWORD_CHARS.to_string()) required="" > @@ -222,6 +223,7 @@ async fn join_card(cx: &Cx, token: &str, person: Invited) -> Result { type="password" name="password" autocomplete="new-password" + minlength=(izlek_core::auth::MIN_PASSWORD_CHARS.to_string()) required="" > diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index 17732e7..b80e2da 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -1311,7 +1311,7 @@ async fn settings_page(cx: &Cx) -> Result {