3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2013 ecdsa@github
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4.QtGui import *
20 from PyQt4.QtCore import *
21 from electrum.i18n import _
26 def make_password_dialog(self, wallet, msg):
29 self.pw.setEchoMode(2)
30 self.new_pw = QLineEdit()
31 self.new_pw.setEchoMode(2)
32 self.conf_pw = QLineEdit()
33 self.conf_pw.setEchoMode(2)
37 label.setWordWrap(True)
41 grid.setColumnMinimumWidth(0, 70)
42 grid.setColumnStretch(1,1)
45 lockfile = ":icons/lock.png" if wallet.use_encryption else ":icons/unlock.png"
46 logo.setPixmap(QPixmap(lockfile).scaledToWidth(36))
47 logo.setAlignment(Qt.AlignCenter)
49 grid.addWidget(logo, 0, 0)
50 grid.addWidget(label, 0, 1, 1, 2)
55 grid.setColumnMinimumWidth(0, 250)
56 grid.setColumnStretch(1,1)
58 if wallet.use_encryption:
59 grid.addWidget(QLabel(_('Password')), 0, 0)
60 grid.addWidget(self.pw, 0, 1)
62 grid.addWidget(QLabel(_('New Password')), 1, 0)
63 grid.addWidget(self.new_pw, 1, 1)
65 grid.addWidget(QLabel(_('Confirm Password')), 2, 0)
66 grid.addWidget(self.conf_pw, 2, 1)
70 vbox.addLayout(ok_cancel_buttons(self))
74 def run_password_dialog(self, wallet, parent):
77 QMessageBox.information(parent, _('Error'), _('No seed'), _('OK'))
80 if not self.exec_(): return
82 password = unicode(self.pw.text()) if wallet.use_encryption else None
83 new_password = unicode(self.new_pw.text())
84 new_password2 = unicode(self.conf_pw.text())
87 seed = wallet.decode_seed(password)
89 QMessageBox.warning(parent, _('Error'), _('Incorrect Password'), _('OK'))
92 if new_password != new_password2:
93 QMessageBox.warning(parent, _('Error'), _('Passwords do not match'), _('OK'))
97 wallet.update_password(seed, password, new_password)
99 QMessageBox.warning(parent, _('Error'), _('Failed to update password'), _('OK'))
103 QMessageBox.information(parent, _('Success'), _('Password was updated successfully'), _('OK'))
105 QMessageBox.information(parent, _('Success'), _('This wallet is not encrypted'), _('OK'))
110 class PasswordDialog(QDialog):
112 def __init__(self, wallet, parent):
113 QDialog.__init__(self, parent)
117 msg = (_('Your wallet is encrypted. Use this dialog to change your password.') + ' '\
118 +_('To disable wallet encryption, enter an empty new password.')) \
119 if wallet.use_encryption else _('Your wallet keys are not encrypted')
120 make_password_dialog(self, wallet, msg)
124 run_password_dialog(self, self.wallet, self.parent)