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>
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|