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 and 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 and 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):
76 if wallet and wallet.is_watching_only():
77 QMessageBox.information(parent, _('Error'), _('This is a watching-only wallet'), _('OK'))
78 return False, None, None
81 return False, None, None
83 password = unicode(self.pw.text()) if wallet and wallet.use_encryption else None
84 new_password = unicode(self.new_pw.text())
85 new_password2 = unicode(self.conf_pw.text())
87 if new_password != new_password2:
88 QMessageBox.warning(parent, _('Error'), _('Passwords do not match'), _('OK'))
90 return run_password_dialog(self, wallet, parent)
95 return True, password, new_password
99 class PasswordDialog(QDialog):
101 def __init__(self, wallet, parent):
102 QDialog.__init__(self, parent)
106 self.setWindowTitle(_("Set Password"))
107 msg = (_('Your wallet is encrypted. Use this dialog to change your password.') + ' '\
108 +_('To disable wallet encryption, enter an empty new password.')) \
109 if wallet.use_encryption else _('Your wallet keys are not encrypted')
110 self.setLayout(make_password_dialog(self, wallet, msg))
114 ok, password, new_password = run_password_dialog(self, self.wallet, self.parent)
119 self.wallet.check_password(password)
121 QMessageBox.warning(self.parent, _('Error'), _('Incorrect Password'), _('OK'))
122 return False, None, None
125 self.wallet.update_password(password, new_password)
127 import traceback, sys
128 traceback.print_exc(file=sys.stdout)
129 QMessageBox.warning(self.parent, _('Error'), _('Failed to update password'), _('OK'))
133 QMessageBox.information(self.parent, _('Success'), _('Password was updated successfully'), _('OK'))
135 QMessageBox.information(self.parent, _('Success'), _('This wallet is not encrypted'), _('OK'))