public void ReadWrite() { string username; SecureString password; DeleteCredentials(); Assert.IsFalse(SavedCredentials.TryRetrieveSavedCredentials(out username, out password)); Assert.IsNull(username); Assert.IsNull(password); SavedCredentials.SaveCredentials("username", "password".ToSecureString()); Assert.IsTrue(SavedCredentials.TryRetrieveSavedCredentials(out username, out password)); Assert.AreEqual("username", username); Assert.AreEqual("password", password.ToOriginalString()); }
void OkClick(object sender, RoutedEventArgs e) { var credentials = new NetworkCredential(username.Text, password.Password); if (proxyTester.TestCredentials(credentials)) { credentialStore.Credentials = credentials; if (saveCredentials.IsChecked.GetValueOrDefault(false)) { SavedCredentials.SaveCredentials(username.Text, password.SecurePassword); } Close(); } else { MessageBox.Show(this, "The supplied username and password were not accepted by the proxy server", "Credentials failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void SaveCredentials(NetworkCredential credentials) { SavedCredentials.SaveCredentials(credentials.UserName, credentials.SecurePassword); }