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);
}
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);
}
Aggregations