Browse Source

qml: wip single password

patch-4
Sander van Grieken 3 years ago
parent
commit
70cf44ccec
  1. 2
      electrum/gui/qml/components/OpenWallet.qml
  2. 2
      electrum/gui/qml/components/wizard/WCWalletPassword.qml
  3. 4
      electrum/gui/qml/qeconfig.py
  4. 12
      electrum/gui/qml/qedaemon.py
  5. 14
      electrum/gui/qml/qewallet.py
  6. 17
      electrum/gui/qml/qewalletdb.py

2
electrum/gui/qml/components/OpenWallet.qml

@ -108,6 +108,7 @@ Pane {
unlockButton.enabled = false
_unlockClicked = true
wallet_db.password = password.text
wallet_db.verify()
openwalletdialog.forceActiveFocus()
}
@ -132,6 +133,7 @@ Pane {
}
Component.onCompleted: {
wallet_db.verify()
password.forceActiveFocus()
}
}

2
electrum/gui/qml/components/wizard/WCWalletPassword.qml

@ -3,7 +3,7 @@ import QtQuick.Layouts 1.0
import QtQuick.Controls 2.1
WizardComponent {
valid: password1.text === password2.text
valid: password1.text === password2.text && password1.text.length > 4
onAccept: {
wizard_data['password'] = password1.text

4
electrum/gui/qml/qeconfig.py

@ -90,12 +90,14 @@ class QEConfig(AuthMixin, QObject):
def pinCode(self, pin_code):
if pin_code == '':
self.pinCodeRemoveAuth()
else:
self.config.set_key('pin_code', pin_code, True)
self.pinCodeChanged.emit()
@auth_protect(method='wallet')
def pinCodeRemoveAuth(self):
pass # no-op
self.config.set_key('pin_code', '', True)
self.pinCodeChanged.emit()
useGossipChanged = pyqtSignal()
@pyqtProperty(bool, notify=useGossipChanged)

12
electrum/gui/qml/qedaemon.py

@ -4,7 +4,7 @@ from decimal import Decimal
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl
from PyQt5.QtCore import Qt, QAbstractListModel, QModelIndex
from electrum.util import register_callback, get_new_wallet_name, WalletFileException
from electrum.util import register_callback, get_new_wallet_name, WalletFileException, standardize_path
from electrum.logging import get_logger
from electrum.wallet import Wallet, Abstract_Wallet
from electrum.storage import WalletStorage, StorageReadWriteError
@ -130,12 +130,17 @@ class QEDaemon(AuthMixin, QObject):
if self._path is None:
return
self._path = standardize_path(self._path)
self._logger.debug('load wallet ' + str(self._path))
if path not in self.daemon._wallets:
if not password:
password = self._password
if self._path not in self.daemon._wallets:
# pre-checks, let walletdb trigger any necessary user interactions
self._walletdb.path = self._path
self._walletdb.password = password
self._walletdb.verify()
if not self._walletdb.ready:
return
@ -144,6 +149,7 @@ class QEDaemon(AuthMixin, QObject):
if wallet != None:
self._loaded_wallets.add_wallet(wallet=wallet)
self._current_wallet = QEWallet.getInstanceFor(wallet)
self._current_wallet.password = password
self.walletLoaded.emit()
if self.daemon.config.get('single_password'):
@ -218,3 +224,5 @@ class QEDaemon(AuthMixin, QObject):
assert self._use_single_password
self._logger.debug('about to set password to %s for ALL wallets' % password)
self.daemon.update_password_for_directory(old_password=self._password, new_password=password)
self._password = password

14
electrum/gui/qml/qewallet.py

@ -545,10 +545,10 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
if storage.is_encrypted_with_hw_device():
return
self._logger.debug('Ok to set password for wallet with path %s' % storage.path)
if password:
enc_version = StorageEncryptionVersion.USER_PASSWORD
else:
enc_version = StorageEncryptionVersion.PLAINTEXT
storage.set_password(password, enc_version=enc_version)
self.wallet.save_db()
self._logger.debug(f'Ok to set password from {self.password} to {password} for wallet with path {storage.path}')
try:
self.wallet.update_password(self.password, password, encrypt_storage=True)
self.password = password
except InvalidPassword as e:
self._logger.exception(repr(e))

17
electrum/gui/qml/qewalletdb.py

@ -59,10 +59,6 @@ class QEWalletDB(QObject):
self.reset()
self._path = wallet_path
self.load_storage()
if self._storage:
self.load_db()
self.pathChanged.emit(self._ready)
@pyqtProperty(bool, notify=needsPasswordChanged)
@ -101,12 +97,6 @@ class QEWalletDB(QObject):
self._password = wallet_password
self.passwordChanged.emit()
self.load_storage()
if self._storage:
self.needsPassword = False
self.load_db()
@pyqtProperty(bool, notify=requiresSplitChanged)
def requiresSplit(self):
return self._requiresSplit
@ -125,6 +115,11 @@ class QEWalletDB(QObject):
def ready(self):
return self._ready
@pyqtSlot()
def verify(self):
self.load_storage()
if self._storage:
self.load_db()
@pyqtSlot()
def doSplit(self):
@ -226,5 +221,3 @@ class QEWalletDB(QObject):
except Exception as e:
self._logger.error(str(e))
self.createError.emit(str(e))

Loading…
Cancel
Save