From 8896723ff2d203aeb036baffb356f6da7305d841 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 28 Jul 2021 16:57:54 +0200 Subject: [PATCH] fix broken `passwordsMatchAndSufficientProperty` which didn't update more than once --- .../CreateNewVaultPasswordController.java | 2 +- .../ChangePasswordController.java | 2 +- .../ui/common/NewPasswordController.java | 29 ++++++++++--------- .../RecoveryKeyResetPasswordController.java | 4 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java index cd66175d6..627793d6e 100644 --- a/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java +++ b/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java @@ -107,7 +107,7 @@ public class CreateNewVaultPasswordController implements FxController { @FXML public void initialize() { - readyToCreateVault.bind(newPasswordSceneController.passwordsMatchAndSufficientProperty().and(recoveryKeyChoice.selectedToggleProperty().isNotNull()).and(processing.not())); + readyToCreateVault.bind(newPasswordSceneController.goodPasswordProperty().and(recoveryKeyChoice.selectedToggleProperty().isNotNull()).and(processing.not())); window.setOnHiding(event -> { newPasswordSceneController.passwordField.wipe(); newPasswordSceneController.reenterField.wipe(); diff --git a/src/main/java/org/cryptomator/ui/changepassword/ChangePasswordController.java b/src/main/java/org/cryptomator/ui/changepassword/ChangePasswordController.java index ccc0184ac..54519f21f 100644 --- a/src/main/java/org/cryptomator/ui/changepassword/ChangePasswordController.java +++ b/src/main/java/org/cryptomator/ui/changepassword/ChangePasswordController.java @@ -62,7 +62,7 @@ public class ChangePasswordController implements FxController { public void initialize() { BooleanBinding checkboxNotConfirmed = finalConfirmationCheckbox.selectedProperty().not(); BooleanBinding oldPasswordFieldEmpty = oldPasswordField.textProperty().isEmpty(); - finishButton.disableProperty().bind(checkboxNotConfirmed.or(oldPasswordFieldEmpty).or(newPasswordController.passwordsMatchAndSufficientProperty().not())); + finishButton.disableProperty().bind(checkboxNotConfirmed.or(oldPasswordFieldEmpty).or(newPasswordController.goodPasswordProperty().not())); window.setOnHiding(event -> { oldPasswordField.wipe(); newPasswordController.passwordField.wipe(); diff --git a/src/main/java/org/cryptomator/ui/common/NewPasswordController.java b/src/main/java/org/cryptomator/ui/common/NewPasswordController.java index 13e59f2cd..caa0962f8 100644 --- a/src/main/java/org/cryptomator/ui/common/NewPasswordController.java +++ b/src/main/java/org/cryptomator/ui/common/NewPasswordController.java @@ -4,12 +4,12 @@ import com.tobiasdiez.easybind.EasyBind; import org.cryptomator.ui.controls.FontAwesome5IconView; import org.cryptomator.ui.controls.NiceSecurePasswordField; -import javafx.beans.Observable; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ReadOnlyBooleanProperty; -import javafx.beans.property.ReadOnlyBooleanWrapper; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.fxml.FXML; import javafx.scene.control.Label; @@ -20,7 +20,7 @@ public class NewPasswordController implements FxController { private final ResourceBundle resourceBundle; private final PasswordStrengthUtil strengthRater; private final IntegerProperty passwordStrength = new SimpleIntegerProperty(-1); - private final ReadOnlyBooleanWrapper passwordsMatchAndSufficient = new ReadOnlyBooleanWrapper(); + private final BooleanProperty goodPassword = new SimpleBooleanProperty(); public NiceSecurePasswordField passwordField; public NiceSecurePasswordField reenterField; @@ -50,11 +50,10 @@ public class NewPasswordController implements FxController { passwordMatchLabel.graphicProperty().bind(Bindings.when(passwordsMatch.and(reenterFieldNotEmpty)).then(passwordMatchCheckmark).otherwise(passwordMatchCross)); passwordMatchLabel.textProperty().bind(Bindings.when(passwordsMatch.and(reenterFieldNotEmpty)).then(resourceBundle.getString("newPassword.passwordsMatch")).otherwise(resourceBundle.getString("newPassword.passwordsDoNotMatch"))); - passwordField.textProperty().addListener(this::passwordsDidChange); - reenterField.textProperty().addListener(this::passwordsDidChange); + BooleanBinding sufficientStrength = Bindings.createBooleanBinding(this::sufficientStrength, passwordField.textProperty()); + goodPassword.bind(passwordsMatch.and(sufficientStrength)); } - private FontAwesome5IconView getIconViewForPasswordStrengthLabel() { if (passwordField.getCharacters().length() == 0) { return null; @@ -67,22 +66,24 @@ public class NewPasswordController implements FxController { } } - private void passwordsDidChange(@SuppressWarnings("unused") Observable observable) { - if (passwordFieldsMatch() && strengthRater.fulfillsMinimumRequirements(passwordField.getCharacters())) { - passwordsMatchAndSufficient.setValue(true); - } - } - private boolean passwordFieldsMatch() { return CharSequence.compare(passwordField.getCharacters(), reenterField.getCharacters()) == 0; } - public ReadOnlyBooleanProperty passwordsMatchAndSufficientProperty() { - return passwordsMatchAndSufficient.getReadOnlyProperty(); + private boolean sufficientStrength() { + return strengthRater.fulfillsMinimumRequirements(passwordField.getCharacters()); } /* Getter/Setter */ + public ReadOnlyBooleanProperty goodPasswordProperty() { + return goodPassword; + } + + public boolean isGoodPassword() { + return goodPassword.get(); + } + public IntegerProperty passwordStrengthProperty() { return passwordStrength; } diff --git a/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java b/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java index a2319ba3c..705991287 100644 --- a/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java +++ b/src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java @@ -86,11 +86,11 @@ public class RecoveryKeyResetPasswordController implements FxController { /* Getter/Setter */ public ReadOnlyBooleanProperty validPasswordProperty() { - return newPasswordController.passwordsMatchAndSufficientProperty(); + return newPasswordController.goodPasswordProperty(); } public boolean isValidPassword() { - return newPasswordController.passwordsMatchAndSufficientProperty().get(); + return newPasswordController.isGoodPassword(); } }