Merge pull request #10345 from f321x/enforce_unified_password_qml_button
qml: limit creation of new wallets to existing password
This commit is contained in:
@@ -564,6 +564,8 @@ class Daemon(Logger):
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
self.update_recently_opened_wallets(path, remove=True)
|
||||
if self.config.CURRENT_WALLET == path:
|
||||
self.config.CURRENT_WALLET = None
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -665,11 +667,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):
|
||||
@@ -708,9 +711,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(
|
||||
@@ -726,13 +731,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