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 .Journal import LegacyJournal
|
||||||
from .prompt import create_password
|
from .prompt import create_password
|
||||||
|
|
||||||
|
from jrnl.exception import JrnlException
|
||||||
|
from jrnl.exception import JrnlExceptionMessage
|
||||||
|
|
||||||
|
|
||||||
def make_key(password):
|
def make_key(password):
|
||||||
password = password.encode("utf-8")
|
password = password.encode("utf-8")
|
||||||
|
@ -53,11 +56,11 @@ def decrypt_content(
|
||||||
password = getpass.getpass()
|
password = getpass.getpass()
|
||||||
result = decrypt_func(password)
|
result = decrypt_func(password)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
if result is not None:
|
|
||||||
return result
|
if result is None:
|
||||||
else:
|
raise JrnlException(JrnlExceptionMessage.PasswordMaxTriesExceeded)
|
||||||
print("Extremely wrong password.", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
return result
|
||||||
|
|
||||||
|
|
||||||
class EncryptedJournal(Journal):
|
class EncryptedJournal(Journal):
|
||||||
|
@ -121,15 +124,11 @@ class EncryptedJournal(Journal):
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_journal(cls, other: Journal):
|
def from_journal(cls, other: Journal):
|
||||||
new_journal = super().from_journal(other)
|
new_journal = super().from_journal(other)
|
||||||
try:
|
new_journal.password = (
|
||||||
new_journal.password = (
|
other.password
|
||||||
other.password
|
if hasattr(other, "password")
|
||||||
if hasattr(other, "password")
|
else create_password(other.name)
|
||||||
else create_password(other.name)
|
)
|
||||||
)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("[Interrupted while creating new journal]", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return new_journal
|
return new_journal
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,10 @@ class JrnlExceptionMessage(Enum):
|
||||||
{config_file}
|
{config_file}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PasswordMaxTriesExceeded = """
|
||||||
|
Too many attempts with wrong password.
|
||||||
|
"""
|
||||||
|
|
||||||
SomeTest = """
|
SomeTest = """
|
||||||
Some error or something
|
Some error or something
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue