diff --git a/src/KeyKeeper/PasswordEntryDialog.axaml b/src/KeyKeeper/PasswordEntryDialog.axaml
new file mode 100644
index 0000000..6481f11
--- /dev/null
+++ b/src/KeyKeeper/PasswordEntryDialog.axaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/KeyKeeper/PasswordEntryDialog.axaml.cs b/src/KeyKeeper/PasswordEntryDialog.axaml.cs
new file mode 100644
index 0000000..612c416
--- /dev/null
+++ b/src/KeyKeeper/PasswordEntryDialog.axaml.cs
@@ -0,0 +1,36 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace KeyKeeper
+{
+ public partial class PasswordEntryDialog : Window
+ {
+ public string Password { get; private set; } = "";
+ public bool Opened { get; private set; } = false;
+
+ public PasswordEntryDialog()
+ {
+ InitializeComponent();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ private void OpenButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
+ {
+ var passwordBox = this.FindControl("PasswordBox");
+ Password = passwordBox?.Text ?? "";
+ Opened = true;
+ Close();
+ }
+
+ private void CancelButton_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
+ {
+ Opened = false;
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/KeyKeeper/RepositoryWindow.axaml.cs b/src/KeyKeeper/RepositoryWindow.axaml.cs
index 5bb3fc9..1a4e1bd 100644
--- a/src/KeyKeeper/RepositoryWindow.axaml.cs
+++ b/src/KeyKeeper/RepositoryWindow.axaml.cs
@@ -7,9 +7,10 @@ using KeyKeeper.PasswordStore.Crypto;
namespace KeyKeeper;
-public partial class RepositoryWindow: Window
+public partial class RepositoryWindow : Window
{
- public IPassStore? PassStore { private get; init; }
+ public IPassStore? PassStore { get; init; }
+ public string? MasterPassword { get; init; } //
public RepositoryWindow()
{
@@ -19,7 +20,12 @@ public partial class RepositoryWindow: Window
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
- if (PassStore!.Locked)
- PassStore.Unlock(new CompositeKey("blablabla", null));
+
+ //
+ if (PassStore != null && PassStore.Locked && !string.IsNullOrEmpty(MasterPassword))
+ {
+ var compositeKey = new CompositeKey(MasterPassword, null);
+ PassStore.Unlock(compositeKey);
+ }
}
}
\ No newline at end of file
diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs
index 58f1cb7..6abb269 100644
--- a/src/KeyKeeper/Views/MainWindow.axaml.cs
+++ b/src/KeyKeeper/Views/MainWindow.axaml.cs
@@ -4,6 +4,7 @@ using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using KeyKeeper.PasswordStore;
+using KeyKeeper.PasswordStore.Crypto;
using KeyKeeper.ViewModels;
using System;
using System.Collections.Generic;
@@ -21,7 +22,6 @@ namespace KeyKeeper.Views
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
{
- // 1. Открываем проводник
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Создать новое хранилище паролей",
@@ -29,34 +29,32 @@ namespace KeyKeeper.Views
DefaultExtension = "kkp",
FileTypeChoices = new[]
{
- new FilePickerFileType("Хранилище KeyKeeper")
- {
- Patterns = new[] { "*.kkp" }
- }
- }
+ new FilePickerFileType("Хранилище KeyKeeper")
+ {
+ Patterns = new[] { "*.kkp" }
+ }
+ }
});
if (file != null)
{
if (file.TryGetLocalPath() is string path)
{
- // 2. Открываем окно с паролем
var passwordDialog = new PasswordDialog();
await passwordDialog.ShowDialog(this);
-
- // 3. Если нажали "Создать"
- if (passwordDialog.Created)
+ if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
{
- // 4. Создаем хранилище с паролем
- var compositeKey = new PasswordStore.Crypto.CompositeKey(passwordDialog.Password, null);
- (DataContext as MainWindowViewModel)!.CreateVault(path);
-
- // 5. Открываем окно хранилища
- OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
- {
- Key = compositeKey,
- LockTimeoutSeconds = 800,
- }));
+ var compositeKey = new CompositeKey(passwordDialog.Password, null);
+ var passStoreAccessor = new PassStoreFileAccessor(
+ filename: path,
+ create: true,
+ createOptions: new StoreCreationOptions()
+ {
+ Key = compositeKey,
+ LockTimeoutSeconds = 800
+ });
+ IPassStore passStore = passStoreAccessor;
+ OpenRepositoryWindow(passStore, passwordDialog.Password);
}
}
}
@@ -64,22 +62,21 @@ namespace KeyKeeper.Views
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
{
- // Открываем диалог выбора файла
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Открыть хранилище паролей",
AllowMultiple = false,
FileTypeFilter = new[]
{
- new FilePickerFileType("Хранилище KeyKeeper")
- {
- Patterns = new[] { "*.kkp" }
- },
- new FilePickerFileType("Все файлы")
- {
- Patterns = new[] { "*.*" }
- }
- }
+ new FilePickerFileType("Хранилище KeyKeeper")
+ {
+ Patterns = new[] { "*.kkp" }
+ },
+ new FilePickerFileType("Все файлы")
+ {
+ Patterns = new[] { "*.*" }
+ }
+ }
});
if (files.Count > 0)
@@ -87,20 +84,32 @@ namespace KeyKeeper.Views
var file = files[0];
if (file.TryGetLocalPath() is string path)
{
- (DataContext as MainWindowViewModel)!.OpenVault(path);
- OpenRepositoryWindow(new PassStoreFileAccessor(path, false, null));
+ var passwordDialog = new PasswordEntryDialog();
+ await passwordDialog.ShowDialog(this);
+ if (passwordDialog.Opened && !string.IsNullOrEmpty(passwordDialog.Password))
+ {
+ var passStoreAccessor = new PassStoreFileAccessor(
+ filename: path,
+ create: false,
+ createOptions: null);
+ IPassStore passStore = passStoreAccessor;
+ (DataContext as MainWindowViewModel)!.OpenVault(path);
+ OpenRepositoryWindow(passStore, passwordDialog.Password);
+ }
}
}
}
- private void OpenRepositoryWindow(IPassStore store)
+ private void OpenRepositoryWindow(IPassStore passStore, string masterPassword)
{
var repositoryWindow = new RepositoryWindow()
{
DataContext = this.DataContext,
- PassStore = store,
+ PassStore = passStore,
+ MasterPassword = masterPassword,
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
+
repositoryWindow.Closed += (s, e) => this.Show();
repositoryWindow.Show();
this.Hide();