From 85789f7097f7b94b090dfbb8881147ad35ccb921 Mon Sep 17 00:00:00 2001 From: George Patrut Date: Tue, 27 Feb 2024 10:08:28 +0100 Subject: [PATCH] added password generator dialog --- .../ViewModels/Pages/DashboardViewModel.cs | 10 +- .../Dialogs/PasswordGeneratorDialog.xaml | 120 ++++++++++++++++++ .../Dialogs/PasswordGeneratorDialog.xaml.cs | 67 ++++++++++ Orderly/Views/Pages/DashboardPage.xaml | 11 ++ 4 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml create mode 100644 Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml.cs diff --git a/Orderly/ViewModels/Pages/DashboardViewModel.cs b/Orderly/ViewModels/Pages/DashboardViewModel.cs index 425bc8e..b055b42 100644 --- a/Orderly/ViewModels/Pages/DashboardViewModel.cs +++ b/Orderly/ViewModels/Pages/DashboardViewModel.cs @@ -143,6 +143,14 @@ public void SaveEditing(Credential credential) db.SaveChanges(); } + [RelayCommand] + public void GeneratePassword(Credential credential) + { + PasswordGeneratorDialog dialog = new(); + if (dialog.ShowDialog() == false) return; + credential.Password = dialog.GeneratedPassword; + } + public void OnNavigatedFrom() { Task.Factory.StartNew(() => { @@ -169,7 +177,7 @@ public void Initalize() credential.PropertyChanged += OnCredentialPropertyChanged; } } - config.FilteringOptions.PropertyChanged += OnFilteringOptionChanged; + Config.FilteringOptions.PropertyChanged += OnFilteringOptionChanged; SortList(); } diff --git a/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml b/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml new file mode 100644 index 0000000..ce050ac --- /dev/null +++ b/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml.cs b/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml.cs new file mode 100644 index 0000000..5582014 --- /dev/null +++ b/Orderly/Views/Dialogs/PasswordGeneratorDialog.xaml.cs @@ -0,0 +1,67 @@ +using Orderly.Modules; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using Wpf.Ui.Controls; + +namespace Orderly.Views.Dialogs +{ + /// + /// Interaction logic for PasswordGeneratorDialog.xaml + /// + public partial class PasswordGeneratorDialog : FluentWindow + { + public string GeneratedPassword { get; private set; } = string.Empty; + public PasswordGeneratorDialog() + { + InitializeComponent(); + } + + private void btnConfirm_Click(object sender, RoutedEventArgs e) + { + GeneratedPassword = pbPassword.Text; + DialogResult = true; + Close(); + } + + private void btnCancel_Click(object sender, RoutedEventArgs e) + { + DialogResult = false; + Close(); + } + + private void CopyPassword(object sender, RoutedEventArgs e) + { + Clipboard.SetText(GeneratedPassword); + pbPassword.Focus(); + pbPassword.SelectAll(); + } + + private void UpdatePassword(object sender, RoutedEventArgs e) + { + if (cbUpper is null || cbSymbols is null || cbNumbers is null || slLength is null || pbPassword is null) return; + bool upperCase = cbUpper.IsChecked!.Value; + bool symbols = cbSymbols.IsChecked!.Value; + bool numbers = cbNumbers.IsChecked!.Value; + int length = (int)slLength.Value; + + GeneratedPassword = PasswordGenerator.GenerateSecurePassword(length, upperCase, numbers, symbols); + pbPassword.Password = GeneratedPassword; + } + + private void slLength_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + UpdatePassword(this, new()); + } + } +} diff --git a/Orderly/Views/Pages/DashboardPage.xaml b/Orderly/Views/Pages/DashboardPage.xaml index be28ab1..e17dbdd 100644 --- a/Orderly/Views/Pages/DashboardPage.xaml +++ b/Orderly/Views/Pages/DashboardPage.xaml @@ -340,6 +340,17 @@ Opacity=".5" PlaceholderEnabled="True" PlaceholderText="Password..." /> +