From fab26f8c73fbbb2af7cca84164b7ba7ccd7d4dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sof=C3=ADa=20Aritz?= Date: Mon, 6 Mar 2023 00:30:51 +0100 Subject: [PATCH] Show user a password-length indicator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the password is less than 12 characters, the length is shown in red, when it is higher, it is shown in green. Also changed the entropy colors to be more _nuanced_, now they have the following values: [0, 35) = red [35, 60) = orange (60, ∞) = green Finally closes #1. --- src/main.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 604dd4a..dc7b8f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,17 +225,30 @@ impl eframe::App for App { ui.add_space(10.0); ui.horizontal(|ui| { TextEdit::singleline(&mut self.password_buffer).password(true).ui(ui); - if let Some(entropy) = entropy(&self.password_buffer) { - let text = if entropy < 60_f64 { - WidgetText::from(format!("entropy: {:.2}", entropy)) - .color(Color32::from_rgb(220, 88, 42)) - } else { - WidgetText::from(format!("entropy: {:.2}", entropy)) - .color(Color32::from_rgb(144, 238, 144)) - }; + let text = if self.password_buffer.len() < 12 { + WidgetText::from(format!("length: {}", self.password_buffer.len())) + .color(Color32::from_rgb(240, 5, 5)) + } else { + WidgetText::from(format!("length: {}", self.password_buffer.len())) + .color(Color32::from_rgb(144, 238, 144)) + }; + ui.label(text); - ui.label(text); - } + let entropy = entropy(&self.password_buffer) + .or(Some(0.0)) + .unwrap(); + let text = if entropy < 35_f64 { + WidgetText::from(format!("entropy: {:.2}", entropy)) + .color(Color32::from_rgb(240, 5, 5)) + } else if entropy < 60_f64 { + WidgetText::from(format!("entropy: {:.2}", entropy)) + .color(Color32::from_rgb(220, 88, 42)) + } else { + WidgetText::from(format!("entropy: {:.2}", entropy)) + .color(Color32::from_rgb(144, 238, 144)) + }; + + ui.label(text); }); ui.add_space(7.5);