Example #1
0
 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
     }
 }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
        }