From 0cffafcd77da6fc093748b4f021f74a16a6ad0c9 Mon Sep 17 00:00:00 2001 From: renovate-bot Date: Tue, 15 Jul 2025 06:07:18 +0000 Subject: [PATCH 1/2] Update Rust crate zxcvbn to v3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9b4b75c..c1472ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ validator = { version = "0.17.0", features = ["derive"] } # Http client reqwest = "0.12.0" # Password strength estimation -zxcvbn = "2.2.2" +zxcvbn = "3.0.0" # Image processing/conversion image = "0.25.1" # Get the application version From ff578ab849e7a6bb0c681be3c5267e79275e67a4 Mon Sep 17 00:00:00 2001 From: Adrien Date: Tue, 15 Jul 2025 08:02:09 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Use=20of=20the=20`zxcvbn::Sc?= =?UTF-8?q?ore`=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/ui/components/login.rs | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c1472ce..0e4159a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ validator = { version = "0.17.0", features = ["derive"] } # Http client reqwest = "0.12.0" # Password strength estimation -zxcvbn = "3.0.0" +zxcvbn = { version = "3.0.0", features = ["ser"] } # Image processing/conversion image = "0.25.1" # Get the application version diff --git a/src/ui/components/login.rs b/src/ui/components/login.rs index 6545eeb..f244183 100644 --- a/src/ui/components/login.rs +++ b/src/ui/components/login.rs @@ -4,7 +4,7 @@ use const_format::formatcp; use dioxus::prelude::*; use tracing::{debug, error, warn}; use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors}; -use zxcvbn::zxcvbn; +use zxcvbn::{zxcvbn, Score}; use crate::{ domain::model::session::Session, @@ -348,14 +348,14 @@ fn validate_id(id: &Option, process: &Process) -> Result<(), ValidationE } struct PasswordValidationResult { - score: u8, + score: Score, rating: f64, // 0 <= rating <= 1 suggestions: Vec, } impl PasswordValidationResult { pub fn new() -> Self { PasswordValidationResult { - score: 0, + score: Score::Zero, rating: 0.0, suggestions: Vec::::new(), } @@ -366,9 +366,7 @@ fn compute_password_score( password: &str, with_suggestions: Option, ) -> Option { - let Ok(estimate) = zxcvbn(password, &[]) else { - return None; - }; + let estimate = zxcvbn(password, &[]); let mut result = PasswordValidationResult::new(); result.score = estimate.score(); @@ -396,7 +394,7 @@ fn validate_password(password: &Option, process: &Process) -> Result<(), if let Some(password) = password { if let Some(result) = compute_password_score(password, Some(true)) { // TODO: To configuration? - if result.score <= 2 { + if [Score::Zero, Score::One, Score::Two].contains(&result.score) { let mut err = ValidationError::new(TOO_WEAK_PASSWORD_ERROR_NAME); err.add_param(Cow::from("score"), &result.score); err.add_param(Cow::from("rating"), &result.rating);