Search in sources :

Example 1 with PasswordTextField

use of io.bitsquare.gui.components.PasswordTextField in project bitsquare by bitsquare.

the class PasswordView method initialize.

@Override
public void initialize() {
    headline = addTitledGroupBg(root, gridRow, 2, "");
    passwordField = addLabelPasswordTextField(root, gridRow, "Enter password:", Layout.FIRST_ROW_DISTANCE).second;
    passwordField.setValidator(passwordValidator);
    passwordFieldChangeListener = (observable, oldValue, newValue) -> validatePasswords();
    Tuple2<Label, PasswordTextField> tuple2 = addLabelPasswordTextField(root, ++gridRow, "Repeat password:");
    repeatedPasswordLabel = tuple2.first;
    repeatedPasswordField = tuple2.second;
    repeatedPasswordField.setValidator(passwordValidator);
    repeatedPasswordFieldChangeListener = (observable, oldValue, newValue) -> validatePasswords();
    Tuple3<Button, BusyAnimation, Label> tuple = addButtonBusyAnimationLabel(root, ++gridRow, "", 15);
    pwButton = tuple.first;
    BusyAnimation busyAnimation = tuple.second;
    Label deriveStatusLabel = tuple.third;
    pwButton.setDisable(true);
    setText();
    pwButton.setOnAction(e -> {
        String password = passwordField.getText();
        checkArgument(password.length() < 50, "Password must be less then 50 characters.");
        pwButton.setDisable(true);
        deriveStatusLabel.setText("Derive key from password");
        busyAnimation.play();
        KeyCrypterScrypt keyCrypterScrypt;
        Wallet wallet = walletService.getWallet();
        if (wallet.isEncrypted())
            keyCrypterScrypt = (KeyCrypterScrypt) wallet.getKeyCrypter();
        else
            keyCrypterScrypt = ScryptUtil.getKeyCrypterScrypt();
        ScryptUtil.deriveKeyWithScrypt(keyCrypterScrypt, password, aesKey -> {
            deriveStatusLabel.setText("");
            busyAnimation.stop();
            if (wallet.isEncrypted()) {
                if (wallet.checkAESKey(aesKey)) {
                    walletService.decryptWallet(aesKey);
                    tradeWalletService.setAesKey(null);
                    new Popup().feedback("Wallet successfully decrypted and password protection removed.").show();
                    passwordField.setText("");
                    repeatedPasswordField.setText("");
                    walletService.backupWallet();
                } else {
                    pwButton.setDisable(false);
                    new Popup().warning("You entered the wrong password.\n\n" + "Please try entering your password again, carefully checking for typos or spelling errors.").show();
                }
            } else {
                walletService.encryptWallet(keyCrypterScrypt, aesKey);
                tradeWalletService.setAesKey(aesKey);
                new Popup().feedback("Wallet successfully encrypted and password protection enabled.").show();
                passwordField.setText("");
                repeatedPasswordField.setText("");
                walletService.clearBackup();
                walletService.backupWallet();
            }
            setText();
        });
    });
    addTitledGroupBg(root, ++gridRow, 1, "Information", Layout.GROUP_DISTANCE);
    addMultilineLabel(root, gridRow, "With password protection you need to enter your password when" + " withdrawing bitcoin out of your wallet or " + "if you want to view or restore a wallet from seed words as well as at application startup.", Layout.FIRST_ROW_AND_GROUP_DISTANCE);
}
Also used : BusyAnimation(io.bitsquare.gui.components.BusyAnimation) Button(javafx.scene.control.Button) Wallet(org.bitcoinj.core.Wallet) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Label(javafx.scene.control.Label) PasswordTextField(io.bitsquare.gui.components.PasswordTextField) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt)

Example 2 with PasswordTextField

use of io.bitsquare.gui.components.PasswordTextField in project bitsquare by bitsquare.

the class WalletPasswordWindow method addInputFields.

private void addInputFields() {
    Label label = new Label("Enter password:");
    label.setWrapText(true);
    GridPane.setMargin(label, new Insets(3, 0, 0, 0));
    GridPane.setRowIndex(label, ++rowIndex);
    passwordTextField = new PasswordTextField();
    GridPane.setMargin(passwordTextField, new Insets(3, 0, 0, 0));
    GridPane.setRowIndex(passwordTextField, rowIndex);
    GridPane.setColumnIndex(passwordTextField, 1);
    PasswordValidator passwordValidator = new PasswordValidator();
    changeListener = (observable, oldValue, newValue) -> unlockButton.setDisable(!passwordValidator.validate(newValue).isValid);
    passwordTextField.textProperty().addListener(changeListener);
    gridPane.getChildren().addAll(label, passwordTextField);
}
Also used : Insets(javafx.geometry.Insets) PasswordValidator(io.bitsquare.gui.util.validation.PasswordValidator) PasswordTextField(io.bitsquare.gui.components.PasswordTextField)

Aggregations

PasswordTextField (io.bitsquare.gui.components.PasswordTextField)2 BusyAnimation (io.bitsquare.gui.components.BusyAnimation)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 PasswordValidator (io.bitsquare.gui.util.validation.PasswordValidator)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 Wallet (org.bitcoinj.core.Wallet)1 KeyCrypterScrypt (org.bitcoinj.crypto.KeyCrypterScrypt)1