Detect fresh install and guide the user to set an encryption passphrase so they know why they're prompted
This commit is contained in:
parent
327e7882b5
commit
4f773e1c1b
3 changed files with 21 additions and 8 deletions
|
|
@ -14,8 +14,8 @@ class KeyPrompt(QDialog):
|
|||
def __init__(
|
||||
self,
|
||||
parent=None,
|
||||
title: str = "Unlock database",
|
||||
message: str = "Enter SQLCipher key",
|
||||
title: str = "Enter key",
|
||||
message: str = "Enter key",
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle(title)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import QDate, QTimer, Qt, QSettings
|
||||
|
|
@ -37,8 +38,14 @@ class MainWindow(QMainWindow):
|
|||
self.setMinimumSize(1000, 650)
|
||||
|
||||
self.cfg = load_db_config()
|
||||
if not os.path.exists(self.cfg.path):
|
||||
# Fresh database/first time use, so guide the user re: setting a key
|
||||
first_time = True
|
||||
else:
|
||||
first_time = False
|
||||
|
||||
# Always prompt for the key (we never store it)
|
||||
if not self._prompt_for_key_until_valid():
|
||||
if not self._prompt_for_key_until_valid(first_time):
|
||||
sys.exit(1)
|
||||
|
||||
# ---- UI: Left fixed panel (calendar) + right editor -----------------
|
||||
|
|
@ -161,12 +168,18 @@ class MainWindow(QMainWindow):
|
|||
return False
|
||||
return ok
|
||||
|
||||
def _prompt_for_key_until_valid(self) -> bool:
|
||||
def _prompt_for_key_until_valid(self, first_time: bool) -> bool:
|
||||
"""
|
||||
Prompt for the SQLCipher key.
|
||||
"""
|
||||
if first_time:
|
||||
title = "Set an encryption key"
|
||||
message = "Bouquin encrypts your data.\n\nPlease create a strong passphrase to encrypt the notebook.\n\nYou can always change it later!"
|
||||
else:
|
||||
title = "Unlock encrypted notebook"
|
||||
message = "Enter your key to unlock the notebook"
|
||||
while True:
|
||||
dlg = KeyPrompt(self, message="Enter a key to unlock the notebook")
|
||||
dlg = KeyPrompt(self, title, message)
|
||||
if dlg.exec() != QDialog.Accepted:
|
||||
return False
|
||||
self.cfg.key = dlg.key()
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ class SettingsDialog(QDialog):
|
|||
self.accept()
|
||||
|
||||
def _change_key(self):
|
||||
p1 = KeyPrompt(self, title="Change key", message="Enter new key")
|
||||
p1 = KeyPrompt(self, title="Change key", message="Enter a new encryption key")
|
||||
if p1.exec() != QDialog.Accepted:
|
||||
return
|
||||
new_key = p1.key()
|
||||
p2 = KeyPrompt(self, title="Change key", message="Re-enter new key")
|
||||
p2 = KeyPrompt(self, title="Change key", message="Re-enter the new key")
|
||||
if p2.exec() != QDialog.Accepted:
|
||||
return
|
||||
if new_key != p2.key():
|
||||
|
|
@ -92,7 +92,7 @@ class SettingsDialog(QDialog):
|
|||
try:
|
||||
self._db.rekey(new_key)
|
||||
QMessageBox.information(
|
||||
self, "Key changed", "The database key was updated."
|
||||
self, "Key changed", "The notebook was re-encrypted with the new key!"
|
||||
)
|
||||
except Exception as e:
|
||||
QMessageBox.critical(self, "Error", f"Could not change key:\n{e}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue