private void BtnLogIn_Click(object sender, EventArgs e) { //cesta do slozek string accsPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\accs"; string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; string decryptedContent = null; #region inicializace klice pro accs try { RSACryptoServiceProvider RSAacc = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(accsPath + "\\key.xml"); cryptoAccKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAacc.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + accsPath + "\\key.xml"); Application.OpenForms[0].Show(); this.Hide(); } #endregion if (File.Exists(accsPath + "\\" + txtUsername.Text + ".dll")) { StreamReader strmReadAcc = new StreamReader(accsPath + "\\" + txtUsername.Text + ".dll"); decryptedContent = Crypter.Decrypt(strmReadAcc.ReadToEnd(), cryptoAccKey);//rozsifruje string[] accFile = new string[3]; accFile[0] = decryptedContent.Split(';')[0]; accFile[1] = decryptedContent.Split(';')[1]; accFile[2] = decryptedContent.Split(';')[2]; strmReadAcc.Close(); string name = accFile[0]; string pin = accFile[1]; string key = accFile[2]; #region inicializace klice pro bin try { RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(binPath + "\\" + key + "\\" + "key.xml"); cryptoBinKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAbin.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + binPath + "\\" + key + "\\" + "key.xml"); Application.OpenForms[0].Show(); this.Hide(); } #endregion if (pin == txtPIN.Text) { DirectoryInfo dd = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] Folders = dd.GetDirectories(); //Getting directories if (Folders.Count() >= 1) { bool jestliMaAlesponJedenDLL = false; for (int j = 0; j < Folders.Count(); j++) { DirectoryInfo df = new DirectoryInfo(binPath + "\\" + key + "\\" + Folders[j]); //vezme data z direktorie FileInfo[] Files = df.GetFiles("*.dll"); //Getting .dll files if (Files.Count() >= 1) { jestliMaAlesponJedenDLL = true; } } if (jestliMaAlesponJedenDLL == true) { PullForm pullForm = new DokaPass.PullForm(key, cryptoAccKey, cryptoBinKey, txtUsername.Text, this.Width, this.Height, this.Location.X, this.Location.Y); pullForm.Show(); txtPIN.Text = ""; txtUsername.Text = ""; if (Application.OpenForms[0].Name == "Form1") { Application.OpenForms[0].Hide(); } this.Hide(); } else { MessageBox.Show("Data s heslama nejsou"); txtPIN.Text = ""; txtUsername.Text = ""; } } else { MessageBox.Show("Data s heslama nejsou"); txtPIN.Text = ""; txtUsername.Text = ""; } } else { MessageBox.Show("Špatný pin"); txtPIN.Text = ""; } } else { MessageBox.Show(txtUsername.Text + " neexistuje, zadejte správně jméno. :("); txtPIN.Text = ""; txtUsername.Text = ""; } }
private void DataGridView_Refresh() { List <string> dtgridViewData = new List <string>(); dtGridView.Rows.Clear(); dtGridView.ColumnCount = 4; dtGridView.Columns[0].Name = "Název:"; dtGridView.Columns[1].Name = "Username:"******"Heslo:"; dtGridView.Columns[3].Name = "Poznámka:"; string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; DirectoryInfo dd = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] Folders = dd.GetDirectories(); //Getting all folders dtGridView.Rows.Clear(); for (int i = 0; i < Folders.Count(); i++) { DirectoryInfo df = new DirectoryInfo(binPath + "\\" + key + "\\" + Folders[i]); //vezme data z direktorie FileInfo[] Files = df.GetFiles("*.dll"); //Getting all .dll folders if (Files.Count() >= 1) { string[] contentSouboru = new string[4]; for (int j = 0; j < Files.Count(); j++) { switch (Files[j].ToString()) { case "1.dll": StreamReader strmR1 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data1 = null; data1 = strmR1.ReadToEnd(); if (data1 != "" || data1 != " ") { contentSouboru[0] = Crypter.Decrypt(data1, cryptoBinKey); } else { contentSouboru[0] = ""; } strmR1.Close(); break; case "2.dll": StreamReader strmR2 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data2 = null; data2 = strmR2.ReadToEnd(); if (data2 != "" || data2 != " ") { contentSouboru[1] = Crypter.Decrypt(data2, cryptoBinKey); } else { contentSouboru[1] = ""; } strmR2.Close(); break; case "3.dll": StreamReader strmR3 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data3 = null; data3 = strmR3.ReadToEnd(); if (data3 != "" || data3 != " ") { contentSouboru[2] = Crypter.Decrypt(data3, cryptoBinKey); } else { contentSouboru[2] = ""; } strmR3.Close(); break; case "4.dll": StreamReader strmR4 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data4 = null; data4 = strmR4.ReadToEnd(); if (data4 != "" || data4 != " ") { contentSouboru[3] = Crypter.Decrypt(data4, cryptoBinKey); } else { contentSouboru[3] = ""; } strmR4.Close(); break; } } try { if ((contentSouboru[0] != "" && contentSouboru[0] != " ") && (contentSouboru[1] != "" && contentSouboru[1] != " ") && (contentSouboru[2] != "" && contentSouboru[2] != " ") && (contentSouboru[3] != "" && contentSouboru[3] != " ")) { dtGridView.Rows.Add(contentSouboru[0], contentSouboru[1], contentSouboru[2], contentSouboru[3]); } } catch { } } } dtGridView.Refresh(); textbox_fill(); }