Datensicherheit: Backup, Verschlüsselung, App-Sperre (Kapitel 13.3)
Automatisches rollierendes Backup der Datenbank beim Start mit Wiederherstellung über die Einstellungen, versionierte Schema-Migration, optionale Passwort-Verschlüsselung der LiteDB-Datei und eine App-Sperre nach Inaktivität mit eigenem Passwort. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LehrerApp.Data;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Passwort-Abfrage beim Programmstart, wenn die Datenbank verschlüsselt ist (13.3.4).
|
||||
/// Läuft vor <see cref="AppBootstrapper.BuildServices"/>, deshalb ohne DI.
|
||||
/// </summary>
|
||||
public partial class DbPasswordPromptViewModel : ObservableObject
|
||||
{
|
||||
private readonly DatabaseEncryptionService _dbEncryption;
|
||||
private readonly string _dbPath;
|
||||
|
||||
[ObservableProperty] private string _password = "";
|
||||
[ObservableProperty] private string _error = "";
|
||||
|
||||
public Action<string>? OnUnlocked { get; set; }
|
||||
|
||||
public DbPasswordPromptViewModel(DatabaseEncryptionService dbEncryption, string dbPath)
|
||||
{
|
||||
_dbEncryption = dbEncryption;
|
||||
_dbPath = dbPath;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Unlock()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Password)) { Error = "Bitte Passwort eingeben."; return; }
|
||||
if (!_dbEncryption.VerifyPassword(_dbPath, Password))
|
||||
{
|
||||
Error = "Falsches Passwort.";
|
||||
Password = "";
|
||||
return;
|
||||
}
|
||||
OnUnlocked?.Invoke(Password);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user