private void GunaButton1_Click(object sender, EventArgs e) { // string pwd = "Click to reveal.";//dont store unencrypted password this is bool valweb = Internals.validatewebsite(txtwebs.Text.ToLower()); //they are both booleans so i could remove these to lower time and increase speed bool vallgn = Internals.validateuserandpass(txtlgn.Text); //^ bool valps = Internals.validateuserandpass(txtpassw.Text); //^^ if (valweb == true) { if (vallgn == true & valps == true) { // string json = serialize.serilizeitems(id, txtwebs.Text, txtlgn.Text, txtpassw.Text, DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy")); writecsv();// try { var items = new ListViewItem(id.ToString()); //create a list of items to add essentally items.SubItems.Add(txtwebs.Text); //add wevsute to listbox items.SubItems.Add(txtlgn.Text); //add login to listvbox items.SubItems.Add(txtpassw.Text); //add pass items.SubItems.Add(DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy")); //grab the date and time and add it listView1.Items.Add(items); //add all of the items we created } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}"); Internals.writeerro(ex.Message); } } else { MessageBox.Show("You must enter a valid login/password!"); } } else { MessageBox.Show("You must enter a valid website!"); } lbltitleitems.Text = updateitems(listView1);//update every time they click da button id++; }
public void writecsv() { try { //convert all these values to bytes so that i can encrypt it later byte[] _web = Encoding.ASCII.GetBytes(txtwebs.Text); byte[] _usr = Encoding.ASCII.GetBytes(txtlgn.Text); byte[] _lgn = Encoding.ASCII.GetBytes(txtpassw.Text); byte[] _date = Encoding.ASCII.GetBytes(DateTime.Now.ToString("hh:mm:ssss MM/dd/yyyy")); //encyrpt the bytes String _Web = Convert.ToBase64String(Internals.encryptdata(_web, Internals.key, Internals.iv)); String _Usr = Convert.ToBase64String(Internals.encryptdata(_usr, Internals.key, Internals.iv)); String _Pass = Convert.ToBase64String(Internals.encryptdata(_lgn, Internals.key, Internals.iv)); String _Date = Convert.ToBase64String(Internals.encryptdata(_date, Internals.key, Internals.iv)); CsvConfiguration csvConfig = new CsvConfiguration(CultureInfo.CurrentCulture) { HasHeaderRecord = !File.Exists(@"Vault\accounts\accounts.csv") }; var records = new List <Items> { }; records.Add(new Items { ID = id, website = _Web, username = _Usr, password = _Pass, date = _Date }); using (FileStream fileStream = new FileStream(@"Vault\accounts\accounts.csv", FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { using (var writer = new StreamWriter(fileStream)) using (var csv = new CsvWriter(writer, csvConfig)) { csv.WriteRecords(records); } } } catch (Exception ex) { MessageBox.Show("Error! Please check error lo!"); Internals.writeerro(ex.Message); } }