public void Save(PasswordDictionary passwords) { var serializer = new XmlSerializer(typeof(PasswordDictionary)); using (var sw = new StreamWriter(_fileName)) serializer.Serialize(sw, passwords); }
private PasswordDictionary LoadFromFile() { PasswordDictionary passwords; try { var serializer = new XmlSerializer(typeof(PasswordDictionary)); using (var sr = new StreamReader(_fileName)) passwords = (PasswordDictionary)serializer.Deserialize(sr); } catch (InvalidOperationException ex) when(ex.InnerException is XmlException) { // Fail silently as the worst case is just some remembered passwords are lost // the xml file will be regenerated the next time a password is saved. passwords = new PasswordDictionary(); } return(passwords); }
public PasswordManager(IPasswordStore passwordStore) { _passwordStore = passwordStore; _passwords = _passwordStore.Load(); }