From 4b7527bf0c0894fa754052fc4fcc9b828b78be09 Mon Sep 17 00:00:00 2001 From: armin Date: Sun, 11 Aug 2019 18:32:46 +0200 Subject: [PATCH] refactoring PasswordStrengthUtil to use ressource bundle --- .../ui/util/PasswordStrengthUtil.java | 38 +++++++++---------- .../main/resources/i18n/strings.properties | 7 +++- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java b/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java index 0aba6bf40..2f110d54d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java +++ b/main/ui/src/main/java/org/cryptomator/ui/util/PasswordStrengthUtil.java @@ -16,24 +16,25 @@ import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.CornerRadii; import javafx.scene.paint.Color; import org.cryptomator.ui.fxapp.FxApplicationScoped; -import org.cryptomator.ui.l10n.Localization; import javax.inject.Inject; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; @FxApplicationScoped public class PasswordStrengthUtil { private static final int PW_TRUNC_LEN = 100; // truncate very long passwords, since zxcvbn memory and runtime depends vastly on the length + private static final String RESSOURCE_PREFIX = "passwordStrength.messageLabel."; private final Zxcvbn zxcvbn; private final List sanitizedInputs; - private final Localization localization; + private final ResourceBundle resourceBundle; @Inject - public PasswordStrengthUtil(Localization localization) { - this.localization = localization; + public PasswordStrengthUtil(ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; this.zxcvbn = new Zxcvbn(); this.sanitizedInputs = new ArrayList<>(); this.sanitizedInputs.add("cryptomator"); @@ -50,18 +51,18 @@ public class PasswordStrengthUtil { public Color getStrengthColor(Number score) { switch (score.intValue()) { - case 0: - return Color.web("#e74c3c"); - case 1: - return Color.web("#e67e22"); - case 2: - return Color.web("#f1c40f"); - case 3: - return Color.web("#40d47e"); - case 4: - return Color.web("#27ae60"); - default: - return Color.web("#ffffff", 0.5); + case 0: + return Color.web("#e74c3c"); + case 1: + return Color.web("#e67e22"); + case 2: + return Color.web("#f1c40f"); + case 3: + return Color.web("#40d47e"); + case 4: + return Color.web("#27ae60"); + default: + return Color.web("#ffffff", 0.5); } } @@ -76,9 +77,8 @@ public class PasswordStrengthUtil { } public String getStrengthDescription(Number score) { - String key = "initialize.messageLabel.passwordStrength." + score.intValue(); - if (localization.containsKey(key)) { - return localization.getString(key); + if (resourceBundle.containsKey(RESSOURCE_PREFIX + score.intValue())) { + return resourceBundle.getString("passwordStrength.messageLabel." + score.intValue()); } else { return ""; } diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index a10ab728a..f7530a1fd 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -40,4 +40,9 @@ unlock.deleteSavedPasswordDialog.content=The saved password of this vault will b vaultlist.emptyList.onboardingInstruction=Click here to add a vault vaultOptions.mount.readonly=Read-Only vaultOptions.mount.driveName=Drive Name -vaultOptions.mount.customMountFlags=Custom Mount Flags \ No newline at end of file +vaultOptions.mount.customMountFlags=Custom Mount Flags +passwordStrength.messageLabel.0=Very weak +passwordStrength.messageLabel.1=Weak +passwordStrength.messageLabel.2=Fair +passwordStrength.messageLabel.3=Strong +passwordStrength.messageLabel.4=Very strong