private void BtnUpdatePassword_Click(object sender, RoutedEventArgs e) { CheckPassword(); if (newPass1.Password != newPass2.Password) { newPass1.BorderBrush = red; newPass2.BorderBrush = red; MessageBox.Show(Properties.strings.SecuritySettingsPasskeyDoNotMatch, "", MessageBoxButton.OK, MessageBoxImage.Error); } else { newPass1.BorderBrush = norm; newPass2.BorderBrush = norm; btnUpdatePassword.Content = Properties.strings.SecuritySettingsPasskeyButtonUpdate; SecureString newPassKey = newPass1.SecurePassword; if (newPassKey.Length == 0) { newPassKey = null; } string action = newPassKey == null ? Properties.strings.SecuritySettingsRemove : Properties.strings.SecuritySettingsChange; string action1 = newPassKey == null ? Properties.strings.SecuritySettingsRemoving : Properties.strings.SecuritySettingsChanging; PleaseWait wait = new PleaseWait(String.Format(Properties.strings.SecuritySettingsProcessingPasskey, action1)); wait.Show(this); wait.Owner = this; new System.Threading.Thread(() => { System.Threading.Thread.CurrentThread.IsBackground = true; try { CredManifest credMan = new CredManifest(); credMan = CredManifest.GetManifest(); if (manifest.CredentialLocker) { if (!manifest.ChangeEncryptionKey(credMan.Key, newPassKey)) { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = String.Format(Properties.strings.SecuritySettingsProcessedFailedPasskey, action); wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } else { credMan.Key = newPassKey; credMan.Save(); Dispatcher.BeginInvoke((Action) delegate() { wait.Hide(); }); } } else { if (!manifest.ChangeEncryptionKey(pass.SecurePassword, newPassKey)) { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = String.Format(Properties.strings.SecuritySettingsProcessedFailedPasskey, action); wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } else { credMan.Key = newPassKey; credMan.Save(); Dispatcher.BeginInvoke((Action) delegate() { wait.Hide(); }); } } } catch { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = String.Format(Properties.strings.SecuritySettingsProcessedFailedPasskey, action); wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } }).Start(); pass.Password = new String(char.Parse(" "), newPassKey.Length); newPass1.Password = newPass2.Password = ""; CheckPassword(); } }
private void btnUpdatePassword_Click(object sender, RoutedEventArgs e) { checkPassword(); if (newPass1.Password != newPass2.Password) { newPass1.BorderBrush = red; newPass2.BorderBrush = red; MessageBox.Show("Passwords do not match.", "", MessageBoxButton.OK, MessageBoxImage.Error); } else { newPass1.BorderBrush = norm; newPass2.BorderBrush = norm; btnUpdatePassword.Content = "Update password"; // Update the password manifest.CredentialLocker = (bool)chkCredentialLocker.IsChecked; manifest.Save(); string newPassKey = newPass1.Password; if (newPassKey.Length == 0) { newPassKey = null; } string action = newPassKey == null ? "remove" : "change"; string action1 = newPassKey == null ? "Removing" : "Changing"; PleaseWait wait = new PleaseWait(action1 + " password, please wait . . ."); wait.Show(this); wait.Owner = this; new System.Threading.Thread(() => { System.Threading.Thread.CurrentThread.IsBackground = true; try { if (!manifest.ChangeEncryptionKey(pass.Password, newPassKey)) { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = "Unable to " + action + " passkey."; wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } else { Dispatcher.BeginInvoke((Action) delegate() { wait.Hide(); }); } } catch { Dispatcher.BeginInvoke((Action) delegate() { wait.txtInfo.Text = "Unable to " + action + " passkey."; wait.progress.BorderBrush = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Background = new SolidColorBrush(Color.FromRgb(203, 128, 128)); wait.progress.Foreground = new SolidColorBrush(Color.FromRgb(200, 21, 21)); }); } }).Start(); pass.Password = newPassKey; newPass1.Password = newPass2.Password = ""; checkPassword(); } }