public static SecureString AskForPassword(string label, Window owner) { SecureString secureString = null; var passwordDialog = new PasswordDialog(label) { Owner = owner }; if (passwordDialog.ShowDialog() == true) { secureString = new SecureString(); foreach (var character in passwordDialog.Password) { secureString.AppendChar(character); } } passwordDialog.TextPassword.Password = String.Empty; return secureString; }
private bool TryOpenPdf() { if (!HasPdfHeader()) { return(false); } String password = null; do { try { PdfViewer.Open(new MemorySource(_largeBinaryValue.Value), password); TabPdf.Visibility = Visibility.Visible; TabPdf.IsSelected = true; return(true); } catch (MissingOrInvalidPdfPasswordException) { if (password != null) { Messages.ShowError("Invalid password"); } var securePassword = PasswordDialog.AskForPassword("PDF password: ", this); if (securePassword == null) { return(false); } password = securePassword.ToString(); } catch { break; } }while (true); return(false); }
public static SecureString AskForPassword(string label, Window owner) { SecureString secureString = null; var passwordDialog = new PasswordDialog(label) { Owner = owner }; if (passwordDialog.ShowDialog() == true) { secureString = new SecureString(); foreach (var character in passwordDialog.Password) { secureString.AppendChar(character); } } passwordDialog.TextPassword.Password = String.Empty; return(secureString); }