mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
Move error for too many wrong passwords into new handling
This commit is contained in:
parent
101963bba6
commit
aa9343a75c
2 changed files with 17 additions and 14 deletions
|
@ -21,6 +21,9 @@ from .Journal import Journal
|
|||
from .Journal import LegacyJournal
|
||||
from .prompt import create_password
|
||||
|
||||
from jrnl.exception import JrnlException
|
||||
from jrnl.exception import JrnlExceptionMessage
|
||||
|
||||
|
||||
def make_key(password):
|
||||
password = password.encode("utf-8")
|
||||
|
@ -53,11 +56,11 @@ def decrypt_content(
|
|||
password = getpass.getpass()
|
||||
result = decrypt_func(password)
|
||||
attempt += 1
|
||||
if result is not None:
|
||||
|
||||
if result is None:
|
||||
raise JrnlException(JrnlExceptionMessage.PasswordMaxTriesExceeded)
|
||||
|
||||
return result
|
||||
else:
|
||||
print("Extremely wrong password.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
class EncryptedJournal(Journal):
|
||||
|
@ -121,15 +124,11 @@ class EncryptedJournal(Journal):
|
|||
@classmethod
|
||||
def from_journal(cls, other: Journal):
|
||||
new_journal = super().from_journal(other)
|
||||
try:
|
||||
new_journal.password = (
|
||||
other.password
|
||||
if hasattr(other, "password")
|
||||
else create_password(other.name)
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("[Interrupted while creating new journal]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return new_journal
|
||||
|
||||
|
|
|
@ -76,6 +76,10 @@ class JrnlExceptionMessage(Enum):
|
|||
{config_file}
|
||||
"""
|
||||
|
||||
PasswordMaxTriesExceeded = """
|
||||
Too many attempts with wrong password.
|
||||
"""
|
||||
|
||||
SomeTest = """
|
||||
Some error or something
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue