mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Asks for password at creation of .jrnl_config
This commit is contained in:
parent
196531aafc
commit
651f9e5213
1 changed files with 20 additions and 4 deletions
20
jrnl.py
20
jrnl.py
|
@ -19,7 +19,7 @@ import mimetypes
|
||||||
default_config = {
|
default_config = {
|
||||||
'journal': os.path.expanduser("~/journal.txt"),
|
'journal': os.path.expanduser("~/journal.txt"),
|
||||||
'editor': "",
|
'editor': "",
|
||||||
'encrypt': True,
|
'encrypt': False,
|
||||||
'key': "",
|
'key': "",
|
||||||
'default_hour': 9,
|
'default_hour': 9,
|
||||||
'default_minute': 0,
|
'default_minute': 0,
|
||||||
|
@ -73,6 +73,7 @@ class Journal:
|
||||||
consts = pdc.Constants()
|
consts = pdc.Constants()
|
||||||
consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
|
consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
|
||||||
self.dateparse = pdt.Calendar(consts)
|
self.dateparse = pdt.Calendar(consts)
|
||||||
|
self.crypto = None
|
||||||
|
|
||||||
self.entries = self.open()
|
self.entries = self.open()
|
||||||
self.sort()
|
self.sort()
|
||||||
|
@ -104,11 +105,16 @@ class Journal:
|
||||||
self.crypto = AES.new(key, AES.MODE_ECB)
|
self.crypto = AES.new(key, AES.MODE_ECB)
|
||||||
journal_plain = self.crypto.decrypt(journal_encrypted)
|
journal_plain = self.crypto.decrypt(journal_encrypted)
|
||||||
# encrypted files should end with spaces. No spaces, no luck.
|
# encrypted files should end with spaces. No spaces, no luck.
|
||||||
while journal_plain[-1] != " ":
|
attempts = 1
|
||||||
|
while journal_plain and attempts < 3 and journal_plain[-1] != " ":
|
||||||
|
attempts += 1
|
||||||
key = getpass.getpass('Wrong password. Try again: ')
|
key = getpass.getpass('Wrong password. Try again: ')
|
||||||
key = self._block_tail(key)
|
key = self._block_tail(key)
|
||||||
self.crypto = AES.new(key, AES.MODE_ECB)
|
self.crypto = AES.new(key, AES.MODE_ECB)
|
||||||
journal_plain = self.crypto.decrypt(journal_encrypted)
|
journal_plain = self.crypto.decrypt(journal_encrypted)
|
||||||
|
if attempts >= 3:
|
||||||
|
print("Extremely wrong password.")
|
||||||
|
sys.exit(-1)
|
||||||
else:
|
else:
|
||||||
journal_plain = f.read()
|
journal_plain = f.read()
|
||||||
|
|
||||||
|
@ -245,9 +251,19 @@ if __name__ == "__main__":
|
||||||
path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
|
path_query = 'Path to your journal file (leave blank for ~/journal.txt): '
|
||||||
journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt')
|
journal_path = raw_input(path_query).strip() or os.path.expanduser('~/journal.txt')
|
||||||
default_config['journal'] = os.path.expanduser(journal_path)
|
default_config['journal'] = os.path.expanduser(journal_path)
|
||||||
|
|
||||||
|
key = getpass.getpass("Enter password for journal (leave blank for no encryption): ")
|
||||||
|
if key:
|
||||||
|
default_config['encrypt'] = True
|
||||||
|
print("Journal will be encrypted.")
|
||||||
|
print("If you want to, you can store your password in .jrnl_config and will never be bothered about it again.")
|
||||||
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
||||||
with open(config_path, 'w') as f:
|
with open(config_path, 'w') as f:
|
||||||
json.dump(default_config, f, indent=2)
|
json.dump(default_config, f, indent=2)
|
||||||
|
config = default_config
|
||||||
|
if key:
|
||||||
|
config['key'] = key
|
||||||
|
else:
|
||||||
with open(config_path) as f:
|
with open(config_path) as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue