diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs
index 679581c..f786df1 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;
@@ -39,19 +40,28 @@ namespace KeyKeeper.Views
{
if (file.TryGetLocalPath() is string path)
{
- (DataContext as MainWindowViewModel)!.CreateVault(path);
- OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
+ var passwordDialog = new PasswordDialog();
+ await passwordDialog.ShowDialog(this);
+ if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
{
- Key = new PasswordStore.Crypto.CompositeKey("blablabla", null),
- 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);
+ }
}
}
}
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
{
- // Открываем диалог выбора файла
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = "Открыть хранилище паролей",
@@ -74,21 +84,21 @@ namespace KeyKeeper.Views
var file = files[0];
if (file.TryGetLocalPath() is string path)
{
- (DataContext as MainWindowViewModel)!.OpenVault(path);
OpenRepositoryWindow(new PassStoreFileAccessor(path, false, null));
}
}
}
- private void OpenRepositoryWindow(IPassStore store)
+ private void OpenRepositoryWindow(IPassStore passStore)
{
- var repositoryWindow = new RepositoryWindow(new RepositoryWindowViewModel(store))
+ var repositoryWindow = new RepositoryWindow(new RepositoryWindowViewModel(passStore))
{
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
+
repositoryWindow.Closed += (s, e) => this.Show();
repositoryWindow.Show();
this.Hide();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml b/src/KeyKeeper/Views/PasswordDialog.axaml
new file mode 100644
index 0000000..27b58c2
--- /dev/null
+++ b/src/KeyKeeper/Views/PasswordDialog.axaml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml.cs b/src/KeyKeeper/Views/PasswordDialog.axaml.cs
new file mode 100644
index 0000000..7e15c00
--- /dev/null
+++ b/src/KeyKeeper/Views/PasswordDialog.axaml.cs
@@ -0,0 +1,65 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Avalonia.Interactivity;
+
+namespace KeyKeeper.Views
+{
+ public partial class PasswordDialog : Window
+ {
+ public string Password { get; private set; } = "";
+ public bool Created { get; private set; } = false;
+
+ public PasswordDialog()
+ {
+ InitializeComponent();
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ private void CreateButton_Click(object sender, RoutedEventArgs e)
+ {
+ var passwordBox = this.FindControl("PasswordBox");
+ var confirmBox = this.FindControl("ConfirmPasswordBox");
+ var errorText = this.FindControl("ErrorText");
+
+ string password = passwordBox?.Text ?? "";
+ string confirmPassword = confirmBox?.Text ?? "";
+
+ if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmPassword))
+ {
+ ShowError("Password cannot be empty");
+ return;
+ }
+
+ if (password != confirmPassword)
+ {
+ ShowError("Passwords don't match");
+ return;
+ }
+
+ Password = password;
+ Created = true;
+ Close();
+ }
+
+ private void ShowError(string message)
+ {
+ var errorText = this.FindControl("ErrorText");
+ if (errorText != null)
+ {
+ errorText.Text = message;
+ errorText.IsVisible = true;
+ }
+ }
+
+ private void CancelButton_Click(object sender, RoutedEventArgs e)
+ {
+ Created = false;
+ Close();
+ }
+ }
+}