diff --git a/jmclient/jmclient/storage.py b/jmclient/jmclient/storage.py index f3fe454..75c2de4 100644 --- a/jmclient/jmclient/storage.py +++ b/jmclient/jmclient/storage.py @@ -115,6 +115,9 @@ class Storage(object): """ return self._data_checksum != self._get_data_checksum() + def check_password(self, password): + return self._hash.hash == self._hash_password(password, self._hash.salt).hash + def change_password(self, password): if self.read_only: raise StorageError("Cannot change password of read-only file.") diff --git a/jmclient/jmclient/wallet.py b/jmclient/jmclient/wallet.py index 0fe1538..0d5b01b 100644 --- a/jmclient/jmclient/wallet.py +++ b/jmclient/jmclient/wallet.py @@ -873,6 +873,9 @@ class BaseWallet(object): """ raise NotImplementedError() + def check_wallet_passphrase(self, passphrase): + return self._storage.check_password(passphrase) + def change_wallet_passphrase(self, passphrase): self._storage.change_password(passphrase) diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index 4e9f922..0b262ed 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -1817,12 +1817,28 @@ class JMMainWindow(QMainWindow): else: self.initWallet() + def checkPassphrase(self): + match = False + while not match: + text, ok = QInputDialog.getText(self, 'Passphrase check', + 'Enter your passphrase:', + echo=QLineEdit.Password) + if not ok: + return False + pwd = str(text).strip().encode('utf-8') + match = self.wallet_service.check_wallet_passphrase(pwd) + if not match: + JMQtMessageBox(self, + "Wrong passphrase.", mbtype='warn', title="Error") + return True + def changePassphrase(self): if not self.wallet_service: JMQtMessageBox(self, "Cannot change passphrase without loaded wallet.", mbtype="crit", title="Error") return - if not wallet_change_passphrase(self.wallet_service, self.getPassword): + if not (self.checkPassphrase() + and wallet_change_passphrase(self.wallet_service, self.getPassword)): JMQtMessageBox(self, "Failed to change passphrase.", title="Error", mbtype="warn") return