| 1 | using System.Security; |
| 2 | using System.Windows; |
| 3 | |
| 4 | namespace Zipelo.Desktop; |
| 5 | |
| 6 | public partial class PasswordWindow : Window |
| 7 | { |
| 8 | public SecureString? SubmittedPassword { get; private set; } |
| 9 | |
| 10 | public PasswordWindow() |
| 11 | { |
| 12 | InitializeComponent(); |
| 13 | Loaded += (_, _) => Secret.Focus(); |
| 14 | Closed += (_, _) => Secret.Clear(); |
| 15 | } |
| 16 | |
| 17 | public SecureString? TakePassword() |
| 18 | { |
| 19 | var password = SubmittedPassword; |
| 20 | SubmittedPassword = null; |
| 21 | return password; |
| 22 | } |
| 23 | |
| 24 | public void DiscardPassword() |
| 25 | { |
| 26 | SubmittedPassword?.Dispose(); |
| 27 | SubmittedPassword = null; |
| 28 | Secret.Clear(); |
| 29 | } |
| 30 | |
| 31 | private void AcceptPassword(object sender, RoutedEventArgs e) |
| 32 | { |
| 33 | SubmittedPassword = Secret.SecurePassword; |
| 34 | SubmittedPassword.MakeReadOnly(); |
| 35 | Secret.Clear(); |
| 36 | DialogResult = true; |
| 37 | } |
| 38 | } |