private void AddPwd_Click(object sender, EventArgs e) { if (NewPasswordTextbox.Text != "") { if (NewPasswordTextbox.Text == RepeatNewPasswordTextBox.Text) { if (NewPasswordTextbox.Text.Length > 7) { if (Passwords.hashPassword(NewPasswordTextbox.Text)) { this.Close(); } } else { MessageBox.Show("Hasło jest za krótkie!", "Niekompletne dane!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Hasła różnią się od siebie!", "Niekompletne dane!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Podaj hasło!", "Niekompletne dane!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void AddPwd_Click(object sender, EventArgs e) { if (Passwords.getPassword() == "") { setPassword nowe = new setPassword(); nowe.Show(); nowe.FormClosed += delegate { if (Passwords.getPassword() != "") { addItem(); } }; } else { addItem(); // Do poprawienia } }
private void button2_Click(object sender, EventArgs e) { try { if (Passwords.getPassword() != "") { Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);; saveFileDialog1.Filter = "Pliki Szyfratora (*.szyfrator)|*.szyfrator|Pliki tekstowe (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.Title = "Szyfrator - Zapisz plik"; saveFileDialog1.RestoreDirectory = true; byte[] buffer = Encoding.UTF8.GetBytes(Strings.Encrypt(getData(), key, iv)); //byte[] buffer = Encoding.UTF8.GetBytes(getData()); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((myStream = saveFileDialog1.OpenFile()) != null) { myStream.Write(buffer, 0, buffer.Length); myStream.Close(); } } } else { MessageBox.Show("Najpierw dodaj hasła!", "Błąd zapisu", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Problem z zapisem pliku!", "Błąd zapisu", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { //byte[] key = Bytes.GenerateKey(); //byte[] iv = Bytes.GenerateIV(); try { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);; openFileDialog.Filter = "Pliki Szyfratora (*.szyfrator)|*.szyfrator|Pliki tekstowe (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.Title = "Szyfrator - Otwórz plik"; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog.FileName; //Read the contents of the file into a stream var fileStream = openFileDialog.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { fileContent = reader.ReadToEnd(); } //Content.Text = Strings.Decrypt(fileContent, key, iv); passwords = new List <Passwords>(); passwords.Clear(); string input = Strings.Decrypt(fileContent, key, iv); string password = input.Substring(0, input.IndexOf("|password|")); if (password.Length > 0) { Password pass = new Password(); pass.Show(); pass.FormClosed += delegate { if (Passwords.checkPassword(pass.getPassword(), password)) { Passwords.setPassword(password); DialogResult result = MessageBox.Show("Witaj!", "Witaj! Logowanie przebiegło pomyślnie!"); if (result == System.Windows.Forms.DialogResult.OK) { string json = input.Substring(input.IndexOf("|password|") + 10); passwords = JsonConvert.DeserializeObject <List <Passwords> >(json); SetupDataGridView(passwords); } } else { DialogResult result = MessageBox.Show("Hasło nieprawidłowe!", "Logowanie nieudane :("); if (result == System.Windows.Forms.DialogResult.OK) { //this.Close(); } } }; } else { MessageBox.Show("Wybrany plik, nie jest plikiem programu Szyfrator!", "Niewłaściwy plik!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception) { MessageBox.Show("Wybrany plik, nie jest plikiem programu Szyfrator!", "Niewłaściwy plik!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
string getData() { List <Passwords> toSave = new List <Passwords>(); string jsonout = ""; try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i] != null) { Passwords item = new Passwords(); if (dataGridView1.Rows[i].Cells[0].Value != null) { item.index = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value); } else { item.index = 0; } if (dataGridView1.Rows[i].Cells[1].Value != null) { item.name = dataGridView1.Rows[i].Cells[1].Value.ToString(); } else { item.name = ""; } if (dataGridView1.Rows[i].Cells[2].Value != null) { item.login = dataGridView1.Rows[i].Cells[2].Value.ToString(); } else { item.login = ""; } if (dataGridView1.Rows[i].Cells[4].Value != null) { item.password = dataGridView1.Rows[i].Cells[4].Value.ToString(); } else { item.password = ""; } if (dataGridView1.Rows[i].Cells[5].Value != null) { item.email = dataGridView1.Rows[i].Cells[5].Value.ToString(); } else { item.email = ""; } if (dataGridView1.Rows[i].Cells[6].Value != null) { item.notes = dataGridView1.Rows[i].Cells[6].Value.ToString(); } else { item.notes = ""; } toSave.Add(item); } } jsonout = Passwords.getPassword() + "|password|"; jsonout += JsonConvert.SerializeObject(toSave); Console.WriteLine(jsonout); } catch (Exception) { throw; } return(jsonout); }