support unlocking with blank password but throw an error when encrypting with blank password

This commit is contained in:
Lex Berezhny 2019-10-18 12:40:57 -04:00
parent afe24a3e65
commit 180035296e

View file

@ -206,11 +206,17 @@ class Wallet:
return False
def unlock(self, password):
self.encryption_password = password
for account in self.accounts:
if account.encrypted:
if not account.decrypt(password):
return False
if password == "":
# for backwards compatiblity:
# some accounts were encrypted with blank password, this allows
# those accounts to be unlocked but then not encrypted anymore
self.decrypt()
else:
self.encryption_password = password
return True
def lock(self):
@ -232,6 +238,8 @@ class Wallet:
def encrypt(self, password):
assert not self.is_locked, "Cannot re-encrypt a locked wallet, unlock first."
if not password:
raise ValueError("Cannot encrypt with blank password.")
self.encryption_password = password
self.preferences[ENCRYPT_ON_DISK] = True
self.save()