private void ImportButton_Click(object sender, RoutedEventArgs e) { if (DelimitedAccountsTextBox.Text.Length == 0) { DelimitedAccountsTextBox.Focus(); MessageBox.Show("No accounts to import!"); return; } if (DelimiterCharacterTextBox.Text.Length == 0) { DelimiterCharacterTextBox.Focus(); MessageBox.Show("Delimiter character required!"); return; } char delimiter = DelimiterCharacterTextBox.Text[0]; string delimitedAccountsText = DelimitedAccountsTextBox.Text; string[] lines = delimitedAccountsText.Split('\n'); List <Account> accounts = new List <Account>(); foreach (string line in lines) { string[] info = line.Split(delimiter); if (info.Length < 2) { MessageBox.Show("Invalid account format!"); return; } // Remove new lines and white space from info. string username = Regex.Replace(info[0], @"\s+", string.Empty); string password = Regex.Replace(info[1], @"\s+", string.Empty); // Shared secret. if (info.Length > 2 && info[2] != null && info[2] != string.Empty) { string secret = Regex.Replace(info[2], @"\s+", string.Empty); accounts.Add(new Account { Name = username, Password = StringCipher.Encrypt(password, eKey), SharedSecret = StringCipher.Encrypt(secret, eKey) }); } else { accounts.Add(new Account { Name = username, Password = StringCipher.Encrypt(password, eKey) }); } } Utils.ImportAccountsFromList(accounts); Close(); }
public static void PasswordSerialize(List <Account> accounts, string password) { var serializer = new XmlSerializer(accounts.GetType()); MemoryStream memStream = new MemoryStream(); serializer.Serialize(memStream, accounts); string serializedAccounts = Encoding.UTF8.GetString(memStream.ToArray()); string encryptedAccounts = StringCipher.Encrypt(serializedAccounts, password); File.WriteAllText("info.dat", encryptedAccounts); memStream.Close(); }
private void NewAccount() { // User entered info var dialog = new TextDialog(); if (dialog.ShowDialog() == true && dialog.AccountText != "" && dialog.PasswordText != "") { account = dialog.AccountText; string password = dialog.PasswordText; string aviUrl = htmlAviScrape(dialog.UrlText); // If the auto login checkbox was checked, update settings file and global variables. if (dialog.AutoLogAccountIndex == true) { settingsFile.Write("SelectedAcc", (encryptedAccounts.Count + 1).ToString(), "AutoLog"); settingsFile.Write("Selected", "True", "AutoLog"); settingsFile.Write("Recent", "False", "AutoLog"); selected = true; recent = false; selectedAcc = encryptedAccounts.Count + 1; } try { // Encrypt info before saving to file ePassword = StringCipher.Encrypt(password, eKey); encryptedAccounts.Add(new Account() { Name = dialog.AccountText, Password = ePassword, ProfUrl = dialog.UrlText, AviUrl = aviUrl, Description = dialog.DescriptionText }); Utils.Serialize(encryptedAccounts); RefreshWindow(); } catch (Exception m) { MessageBox.Show(m.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); var itemToRemove = encryptedAccounts.Single(r => r.Name == dialog.AccountText); encryptedAccounts.Remove(itemToRemove); Utils.Serialize(encryptedAccounts); NewAccount(); } } }
private void editEntry(object butt) { Button button = butt as Button; int index = Int32.Parse(button.Tag.ToString()); var dialog = new TextDialog(); dialog.AccountText = decryptedAccounts[index].Name; dialog.PasswordText = decryptedAccounts[index].Password; dialog.UrlText = decryptedAccounts[index].ProfUrl; dialog.DescriptionText = decryptedAccounts[index].Description; // Reload slected boolean if (settingsFile.Read("Selected", "AutoLog") == "True") { selected = true; } else { selected = false; } if (selected == true && selectedAcc == index) { dialog.autoLogCheckBox.IsChecked = true; } if (dialog.ShowDialog() == true) { string aviUrl = htmlAviScrape(dialog.UrlText); // If the auto login checkbox was checked, update settings file and global variables. if (dialog.AutoLogAccountIndex == true) { settingsFile.Write("SelectedAcc", button.Tag.ToString(), "AutoLog"); settingsFile.Write("Selected", "True", "AutoLog"); settingsFile.Write("Recent", "False", "AutoLog"); selected = true; recent = false; selectedAcc = index; } else { settingsFile.Write("SelectedAcc", "-1", "AutoLog"); settingsFile.Write("Selected", "False", "AutoLog"); selected = false; selectedAcc = -1; } try { // Encrypt info before saving to file ePassword = StringCipher.Encrypt(dialog.PasswordText, eKey); encryptedAccounts[index].Name = dialog.AccountText; encryptedAccounts[index].Password = ePassword; encryptedAccounts[index].ProfUrl = dialog.UrlText; encryptedAccounts[index].AviUrl = aviUrl; encryptedAccounts[index].Description = dialog.DescriptionText; Utils.Serialize(encryptedAccounts); RefreshWindow(); } catch (Exception m) { MessageBox.Show(m.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); editEntry(butt); } } }
private void ImportButton_Click(object sender, RoutedEventArgs e) { if (DelimitedAccountsTextBox.Text.Length == 0) { DelimitedAccountsTextBox.Focus(); MessageBox.Show("No accounts to import!"); return; } if (DelimiterCharacterTextBox.Text.Length == 0) { DelimiterCharacterTextBox.Focus(); MessageBox.Show("Delimiter character required!"); return; } char delimiter = DelimiterCharacterTextBox.Text[0]; string delimitedAccountsText = DelimitedAccountsTextBox.Text; string[] lines = delimitedAccountsText.Split('\n'); List <Account> accounts = new List <Account>(); int sucessful = 0; List <string> errors = new List <string>(); for (int i = 0; i < lines.Length; i++) { string line = Regex.Replace(lines[i], @"\s+", string.Empty); // Skip empty lines. if (line.Length == 0) { continue; } string[] info = line.Split(delimiter); // Log account error. if (info.Length < 2) { errors.Add(line); continue; } // Shared secret. if (info.Length > 2 && info[2] != null && info[2] != string.Empty) { accounts.Add(new Account { Name = info[0], Password = StringCipher.Encrypt(info[1], eKey), SharedSecret = StringCipher.Encrypt(info[2], eKey) }); } else { accounts.Add(new Account { Name = info[0], Password = StringCipher.Encrypt(info[1], eKey) }); } sucessful++; } Utils.ImportAccountsFromList(accounts); if (errors.Count > 0) { MessageBox.Show("There were " + errors.Count + " problems with import:\n" + String.Join("\n", errors.ToArray())); } Close(); }