PasswordDialogWindow

This commit is contained in:
Chernykh Aleksandr
2025-12-05 00:13:02 +03:00
parent 192eb5c598
commit 67bf3487a0
3 changed files with 84 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="KeyKeeper.Views.PasswordDialog"
Title="Создание хранилища"
Width="300"
Height="200">
<StackPanel Margin="20" VerticalAlignment="Center">
<TextBlock Text="Введите мастер-пароль:" Margin="0,0,0,5"/>
<TextBox x:Name="PasswordBox"
Margin="0,0,0,15"/>
<TextBlock Text="Подтвердите пароль:" Margin="0,0,0,5"/>
<TextBox x:Name="ConfirmBox"
Margin="0,0,0,20"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="10">
<Button Content="Отмена"
Width="80"
Click="OnCancelClick"/>
<Button Content="Создать"
Width="80"
Click="OnCreateClick"/>
</StackPanel>
</StackPanel>
</Window>

View File

@@ -0,0 +1,36 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
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 OnCreateClick(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var passwordBox = this.FindControl<TextBox>("PasswordBox");
Password = passwordBox?.Text ?? "";
Created = true;
Close();
}
private void OnCancelClick(object sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Created = false;
Close();
}
}
}

View File

@@ -21,6 +21,7 @@ namespace KeyKeeper.Views
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
{
// 1. Открываем проводник
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Создать новое хранилище паролей",
@@ -39,12 +40,24 @@ namespace KeyKeeper.Views
{
if (file.TryGetLocalPath() is string path)
{
(DataContext as MainWindowViewModel)!.CreateVault(path);
OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
// 2. Открываем окно с паролем
var passwordDialog = new PasswordDialog();
await passwordDialog.ShowDialog(this);
// 3. Если нажали "Создать"
if (passwordDialog.Created)
{
Key = new PasswordStore.Crypto.CompositeKey("blablabla", null),
LockTimeoutSeconds = 800,
}));
// 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,
}));
}
}
}
}