Show user a password-length indicator

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.
This commit is contained in:
Sofía Aritz 2023-03-06 00:30:51 +01:00
parent b051b923fd
commit fab26f8c73

View file

@ -225,8 +225,22 @@ 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 {
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);
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 {
@ -235,7 +249,6 @@ impl eframe::App for App {
};
ui.label(text);
}
});
ui.add_space(7.5);