diff --git a/WingCryptWPF/MainWindow.xaml.cs b/WingCryptWPF/MainWindow.xaml.cs index 47c6025..8525dd6 100644 --- a/WingCryptWPF/MainWindow.xaml.cs +++ b/WingCryptWPF/MainWindow.xaml.cs @@ -91,6 +91,8 @@ private bool DoEncrypt() return false; } + if (!ConfirmPassword()) return false; + Mouse.OverrideCursor = Cursors.Wait; string headerPath = ((TreeViewItem)fileTreeView.Items[0]).Header.ToString(); @@ -116,10 +118,11 @@ private void ButtonEncrypt_Click(object sender, RoutedEventArgs e) } finally { - fileTreeView.Items.Clear(); Mouse.OverrideCursor = null; } + fileTreeView.Items.Clear(); + MessageBox.Show("Encryption completed.", "Encryption Complete", MessageBoxButton.OK, MessageBoxImage.None); } @@ -274,10 +277,11 @@ private void ButtonEncryptAndDelete_Click(object sender, RoutedEventArgs e) } finally { - fileTreeView.Items.Clear(); Mouse.OverrideCursor = null; } + fileTreeView.Items.Clear(); + MessageBox.Show("Encryption completed.", "Encryption Complete", MessageBoxButton.OK, MessageBoxImage.None); } @@ -307,4 +311,26 @@ private void ButtonDecryptAndDelete_Click(object sender, RoutedEventArgs e) Mouse.OverrideCursor = null; } } + + private bool ConfirmPassword() + { + try + { + string confirm = PasswordDialog.GetPassword(); + + if (confirm == passwordTextBox.Password) + { + return true; + } + else + { + MessageBox.Show($"Passwords did not match. Please try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + return false; + } + } + catch + { + return false; + } + } } \ No newline at end of file diff --git a/WingCryptWPF/PasswordDialog.xaml b/WingCryptWPF/PasswordDialog.xaml new file mode 100644 index 0000000..98d48aa --- /dev/null +++ b/WingCryptWPF/PasswordDialog.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WingCryptWPF/PasswordDialog.xaml.cs b/WingCryptWPF/PasswordDialog.xaml.cs new file mode 100644 index 0000000..3fb9299 --- /dev/null +++ b/WingCryptWPF/PasswordDialog.xaml.cs @@ -0,0 +1,43 @@ +namespace WingCryptWPF; +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 Microsoft.Win32; +/// +/// Interaction logic for PasswordDialog.xaml +/// +public partial class PasswordDialog : Window +{ + public PasswordDialog() + { + InitializeComponent(); + } + + public string Password => passwordTextBox.Password; + + public static string GetPassword() + { + PasswordDialog passwordDialog = new(); + + if (passwordDialog.ShowDialog() == true) + { + return passwordDialog.Password; + } + else throw new Exception("Cancelled."); + } + + private void ButtonConfirm_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } +}