mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-08 17:36:30 +03:00
PasswordDialogWindow
This commit is contained in:
30
src/KeyKeeper/PasswordDialog.axaml
Normal file
30
src/KeyKeeper/PasswordDialog.axaml
Normal 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>
|
||||||
36
src/KeyKeeper/PasswordDialog.axaml.cs
Normal file
36
src/KeyKeeper/PasswordDialog.axaml.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ namespace KeyKeeper.Views
|
|||||||
|
|
||||||
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
|
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
// 1. Открываем проводник
|
||||||
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||||
{
|
{
|
||||||
Title = "Создать новое хранилище паролей",
|
Title = "Создать новое хранилище паролей",
|
||||||
@@ -39,15 +40,27 @@ namespace KeyKeeper.Views
|
|||||||
{
|
{
|
||||||
if (file.TryGetLocalPath() is string path)
|
if (file.TryGetLocalPath() is string path)
|
||||||
{
|
{
|
||||||
|
// 2. Открываем окно с паролем
|
||||||
|
var passwordDialog = new PasswordDialog();
|
||||||
|
await passwordDialog.ShowDialog(this);
|
||||||
|
|
||||||
|
// 3. Если нажали "Создать"
|
||||||
|
if (passwordDialog.Created)
|
||||||
|
{
|
||||||
|
// 4. Создаем хранилище с паролем
|
||||||
|
var compositeKey = new PasswordStore.Crypto.CompositeKey(passwordDialog.Password, null);
|
||||||
(DataContext as MainWindowViewModel)!.CreateVault(path);
|
(DataContext as MainWindowViewModel)!.CreateVault(path);
|
||||||
|
|
||||||
|
// 5. Открываем окно хранилища
|
||||||
OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
|
OpenRepositoryWindow(new PassStoreFileAccessor(path, true, new StoreCreationOptions()
|
||||||
{
|
{
|
||||||
Key = new PasswordStore.Crypto.CompositeKey("blablabla", null),
|
Key = compositeKey,
|
||||||
LockTimeoutSeconds = 800,
|
LockTimeoutSeconds = 800,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
|
private async void OpenExistingVault_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user