mirror of
https://github.com/JoinMarket-Org/joinmarket-clientserver.git
synced 2026-08-17 13:07:51 +02:00
Qt: Add passphrase protection
This commit is contained in:
parent
3316542e1e
commit
bd48c9101a
3 changed files with 23 additions and 1 deletions
|
|
@ -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.")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue