def passphrase_dialog(self, msg, confirm): # If confirm is true, require the user to enter the passphrase twice parent = self.top_level_window() d = WindowModalDialog(parent, _("Enter Passphrase")) if confirm: OK_button = OkButton(d) playout = PasswordLayout(msg=msg, kind=PW_PASSPHRASE, OK_button=OK_button) vbox = QtWidgets.QVBoxLayout() vbox.addLayout(playout.layout()) vbox.addLayout(Buttons(CancelButton(d), OK_button)) d.setLayout(vbox) passphrase = playout.new_password() if d.exec_() else None else: pw = PasswordLineEdit() pw.setMinimumWidth(200) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(WWLabel(msg)) vbox.addWidget(pw) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) passphrase = pw.text() if d.exec_() else None self.passphrase = passphrase self.done.set()
def reset_seed_dialog(self, msg): print_error("In reset_seed_dialog") parent = self.top_level_window() d = WindowModalDialog(parent, _("Enter PIN")) pw = PasswordLineEdit() pw.setMinimumWidth(200) vbox = QtWidgets.QVBoxLayout() vbox.addWidget(WWLabel(msg)) vbox.addWidget(pw) vbox.addLayout(Buttons(CancelButton(d), OkButton(d))) d.setLayout(vbox) passphrase = pw.text() if d.exec_() else None return passphrase
class PasswordLayout: titles = [_("Enter Password"), _("Change Password"), _("Enter Passphrase")] def __init__( self, msg, kind, OK_button, wallet=None, *, permit_empty: bool = True, force_disable_encrypt_cb: bool = False, ): self.wallet = wallet self.permit_empty = bool(permit_empty) self.pw = PasswordLineEdit() self.new_pw = PasswordLineEdit() self.conf_pw = PasswordLineEdit() self.kind = kind self.OK_button = OK_button self.all_lineedits = ( self.pw, self.new_pw, self.conf_pw ) self.pw_strength = None # Will be a QLabel if kind != PW_PASSPHRASE vbox = QtWidgets.QVBoxLayout() label = QtWidgets.QLabel(msg + "\n") label.setWordWrap(True) grid = QtWidgets.QGridLayout() grid.setSpacing(8) grid.setColumnStretch(1, 1) if kind == PW_PASSPHRASE: vbox.addWidget(label) msgs = [_('Passphrase:'), _('Confirm Passphrase:')] else: logo_grid = QtWidgets.QGridLayout() logo_grid.setSpacing(8) logo_grid.setColumnMinimumWidth(0, 70) logo_grid.setColumnStretch(1,1) logo = QtWidgets.QLabel() logo.setAlignment(Qt.AlignCenter) logo_grid.addWidget(logo, 0, 0) logo_grid.addWidget(label, 0, 1, 1, 2) vbox.addLayout(logo_grid) m1 = _('New Password:'******'Password:'******'Confirm Password:'******'Current Password:'******'Show')) f = self.show_cb.font(); f.setPointSize(f.pointSize()-1); self.show_cb.setFont(f) # make font -1 grid.addWidget(self.show_cb, 3, 2, Qt.AlignRight) def toggle_show_pws(): show = self.show_cb.isChecked() for le in self.all_lineedits: le.setEchoMode(QtWidgets.QLineEdit.Password if not show else QtWidgets.QLineEdit.Normal) self.show_cb.toggled.connect(toggle_show_pws) self.encrypt_cb = QtWidgets.QCheckBox(_('Encrypt wallet file')) self.encrypt_cb.setEnabled(False) grid.addWidget(self.encrypt_cb, 4, 0, 1, -1) self.encrypt_cb.setVisible(kind != PW_PASSPHRASE) def enable_OK(): ok = bool(self.new_pw.text() == self.conf_pw.text() and (self.new_pw.text() or self.permit_empty)) OK_button.setEnabled(ok) self.encrypt_cb.setEnabled(ok and bool(self.new_pw.text()) and not force_disable_encrypt_cb) self.new_pw.textChanged.connect(enable_OK) self.conf_pw.textChanged.connect(enable_OK) if not self.permit_empty: enable_OK() # force buttons to OFF state initially. self.vbox = vbox def title(self): return self.titles[self.kind] def layout(self): return self.vbox def pw_changed(self): if not self.pw_strength: return password = self.new_pw.text() if password: colors = {"Weak":"Red", "Medium":"Blue", "Strong":"Green", "Very Strong":"Green"} strength = check_password_strength(password) label = (_("Password Strength") + ": " + "<font color=" + colors[strength] + ">" + strength + "</font>") else: label = "" self.pw_strength.setText(label) def old_password(self): if self.kind == PW_CHANGE: return self.pw.text() or None return None def new_password(self): pw = self.new_pw.text() # Empty passphrases are fine and returned empty. if pw == "" and self.kind != PW_PASSPHRASE: pw = None return pw