qml: enforce use of existing password for wallet creation
When creating a new wallet in a Electrum instance with existing wallets this change forces the user to reuse a password of any existing wallet if `SimpleConfig.WALLET_USE_SINGLE_PASSWORD` is True. This prevents the amount of different passwords from increasing and guides the user towards a single wallet password (the intended default).
This commit is contained in:
@@ -663,11 +663,12 @@ class Daemon(Logger):
|
||||
asyncio.run_coroutine_threadsafe(self.stop(), self.asyncio_loop).result()
|
||||
|
||||
@with_wallet_lock
|
||||
def _check_password_for_directory(self, *, old_password, new_password=None, wallet_dir: str) -> Tuple[bool, bool]:
|
||||
def check_password_for_directory(self, *, old_password, new_password=None, wallet_dir: str) -> Tuple[bool, bool, list[str]]:
|
||||
"""Checks password against all wallets (in dir), returns whether they can be unified and whether they are already.
|
||||
If new_password is not None, update all wallet passwords to new_password.
|
||||
"""
|
||||
assert os.path.exists(wallet_dir), f"path {wallet_dir!r} does not exist"
|
||||
succeeded = []
|
||||
failed = []
|
||||
is_unified = True
|
||||
for filename in os.listdir(wallet_dir):
|
||||
@@ -706,9 +707,11 @@ class Daemon(Logger):
|
||||
if new_password:
|
||||
self.logger.info(f'updating password for wallet: {path!r}')
|
||||
wallet.update_password(old_password_real, new_password, encrypt_storage=True)
|
||||
succeeded.append(path)
|
||||
|
||||
can_be_unified = failed == []
|
||||
is_unified = can_be_unified and is_unified
|
||||
return can_be_unified, is_unified
|
||||
return can_be_unified, is_unified, succeeded
|
||||
|
||||
@with_wallet_lock
|
||||
def update_password_for_directory(
|
||||
@@ -724,13 +727,13 @@ class Daemon(Logger):
|
||||
return False
|
||||
if wallet_dir is None:
|
||||
wallet_dir = os.path.dirname(self.config.get_wallet_path())
|
||||
can_be_unified, is_unified = self._check_password_for_directory(
|
||||
can_be_unified, is_unified, _ = self.check_password_for_directory(
|
||||
old_password=old_password, new_password=None, wallet_dir=wallet_dir)
|
||||
if not can_be_unified:
|
||||
return False
|
||||
if is_unified and old_password == new_password:
|
||||
return True
|
||||
self._check_password_for_directory(
|
||||
self.check_password_for_directory(
|
||||
old_password=old_password, new_password=new_password, wallet_dir=wallet_dir)
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user