Ejemplo n.º 1
0
        private void ListViewPwDat_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (ListViewPwDat.SelectedItem == null)
            {
                return;
            }


            CPwDat selItem = (CPwDat)ListViewPwDat.SelectedItem;

            MessageBoxResult result =
                MessageBox.Show($"Datensatz '{selItem.Title}' löschen ?", "Achtung", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }



            ListPw.Remove(selItem);

            PwDatToListView(TextBoxFilter.Text);

            EncryptFile();

            //Löschen der Ausgangsanzeige
            CPwDat dat = new CPwDat {
                Title = "", WebAdr = "", User = "", PW = "", Opt1 = "", Opt2 = ""
            };

            WriteOutputFields(dat);
        }
Ejemplo n.º 2
0
 private void DeleteRandomData()
 {
     for (int i = ListPw.Count - 1; i >= 0; i--)
     {
         if (ListPw[i].Title.StartsWith("_") && ListPw[i].Opt2.StartsWith("_"))
         {
             ListPw.RemoveAt(i);
         }
     }
 }
Ejemplo n.º 3
0
        private void PwDatToListView(string filterIn)
        {
            string filter         = filterIn.ToUpper();
            int    underlineCount = 0;

            ListViewPwDat.Items.Clear();

            ListPw.Sort();

            if (filter == "")
            {
                foreach (CPwDat item in ListPw)
                {
                    if (item.Title.StartsWith("_") && item.Opt2.StartsWith("_"))  //erster Random-Datensatz
                    {
                        underlineCount++;
                        continue;
                    }

                    ListViewPwDat.Items.Add(new CPwDat {
                        Title = item.Title, User = item.User, PW = item.PW, Opt1 = item.Opt1, Opt2 = item.Opt2, WebAdr = item.WebAdr
                    });
                }
            }
            else
            {
                foreach (CPwDat item in ListPw)
                {
                    if (item.ToString().ToUpper().Contains(filter))
                    {
                        if (item.Title.StartsWith("_") && item.Opt2.StartsWith("_"))  //erster Random-Datensatz
                        {
                            underlineCount++;
                            continue;
                        }
                        ListViewPwDat.Items.Add(new CPwDat {
                            Title = item.Title, User = item.User, PW = item.PW, Opt1 = item.Opt1, Opt2 = item.Opt2, WebAdr = item.WebAdr
                        });
                    }
                }
            }

            ButtonDataCount.Content = "Records: " + (ListPw.Count - underlineCount).ToString();
        }
Ejemplo n.º 4
0
        private void AddRandomData()
        {
            Random rnd = new Random();

            //ToDo File neu beschreiben
            for (int k = 0; k < 2; k++)
            {
                string[] term = new string[6];

                for (int i = 0; i < 6; i++)
                {
                    int len   = rnd.Next(8, 32);
                    int start = rnd.Next(CMyRandom.Chars.Length - len - 1);
                    term[i] = CMyRandom.Chars.Substring(start, len);
                }

                ListPw.Add(new CPwDat {
                    Title = "_" + term[0], WebAdr = term[1], User = term[2], PW = term[3], Opt1 = term[4], Opt2 = "_" + term[5]
                });
            }
        }
Ejemplo n.º 5
0
        private void ButtonInputStore_Click(object sender, RoutedEventArgs e)
        {
            string titleUp = TextBoxTitelIn.Text.Trim().ToUpper();


            if (titleUp == "")
            {
                MessageBox.Show("Titel im Datensatz fehlt");
                return;
            }

            // Durchsuchen der Liste nach dem neuen Titel
            CPwDat dat = ListPw.Find(x => x.Title.ToUpper() == titleUp);

            if (dat != null)
            {
                MessageBoxResult result =
                    MessageBox.Show("Es gibt schon einen Datensatz mit dem Titel\n     " + dat.Title +
                                    "\nÜberschreiben", "Achtung", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                if (result == MessageBoxResult.No)
                {
                    return;
                }

                ListPw.Remove(dat);
            }

            CPwDat newDat = new CPwDat {
                Title = TextBoxTitelIn.Text.Trim(), WebAdr = TextBoxWebAdrIn.Text.Trim(), User = TextBoxUserIn.Text.Trim(), PW = TextBoxPwIn.Text.Trim(), Opt1 = TextBoxOpt1In.Text.Trim(), Opt2 = TextBoxOpt2In.Text.Trim()
            };

            ListPw.Add(newDat);

            PwDatToListView(TextBoxFilter.Text);

            EncryptFile();

            WriteOutputFields(newDat);
        }
Ejemplo n.º 6
0
        private void SimpleTxtToListPw(string pathAndFile)
        {
            ListPw.Clear();

            //AddRandomData();

            string[] s = File.ReadAllLines(pathAndFile);

            //string[] b = s[0].Split(";");

            foreach (string item in s)
            {
                string[] b  = item.Split(";");
                CPwDat   pw = new CPwDat();
                pw.Title  = b[0];
                pw.WebAdr = b[1];
                pw.User   = b[2];
                pw.PW     = b[3];
                pw.Opt1   = b[4];
                pw.Opt2   = b[5];
                ListPw.Add(pw);
            }
        }
Ejemplo n.º 7
0
        private bool DecryptFile()
        {
            bool ok = true;

            // ---------------     Entschlüsseln    -------------------------------
            // Erstelle eine Instanz von AES und weise ihr einen Schlüssel und Initialisierungsvektor zu
            // Wichtig ist hier das Padding, welches wir unbedingt definieren müssen.
            Aes AESCrypto = Aes.Create();

            AESCrypto.Padding = PaddingMode.Zeros;
            AESCrypto.Key     = DoExtendKey((MyPasswordBox.Password + TextBoxUser.Text + CMyRandom.MoreKey).Substring(0, 32), 32);
            AESCrypto.IV      = DoCreateBlocksize((TextBoxUser.Text + CMyRandom.MoreIV).Substring(0, 16), 16);


            try
            {
                // Die neue Datei hat den gleichen Namen, allerdings die Dateiendung .txt
                // Achtung: Die Originaldatei wird überschrieben, wenn diese sich im gleichen Pfad befindet!
                //     string neueDatei = System.IO.Path.ChangeExtension(openFileDialog1.FileName, ".txt");
                // Erstelle einen Inputstream, Outputstream und Cryptostream

                FileStream inputStream = new FileStream(PmPath + "\\" + "MyPW.txt", FileMode.Open);



                //FileStream outputStream = new FileStream(PmPath + "\\" + "Mp2.txt", FileMode.Create);
                CryptoStream cStream = new CryptoStream(inputStream, AESCrypto.CreateDecryptor(), CryptoStreamMode.Read);

                // Entschlüssele nun jedes Byte bis zum Dateiende
                int data;
                //while ((data = cStream.ReadByte()) != -1)
                //    outputStream.WriteByte((byte)data);

                StringBuilder sb = new StringBuilder();

                while ((data = cStream.ReadByte()) != -1)
                {
                    sb.Append(((char)data).ToString());
                }

                string[] s = sb.ToString().Split("\n");

                ListPw.Clear();

                foreach (string item in s)
                {
                    string[] b = item.Split(";");
                    if (b.Length == 6)
                    {
                        CPwDat pw = new CPwDat();
                        pw.Title  = b[0].Trim();
                        pw.WebAdr = b[1].Trim();
                        pw.User   = b[2].Trim();
                        pw.PW     = b[3].Trim();
                        pw.Opt1   = b[4].Trim();
                        pw.Opt2   = b[5].Trim();
                        ListPw.Add(pw);
                    }
                    else
                    {
                        if (ListPw.Count == 0)
                        {
                            MessageBox.Show("Passwort passt nicht\n\nPasswort oder Directory ändern\n\n" +
                                            "Um die Daten neu anzulegen, muss die Datei 'MyPW.txt' gelöscht werden\n" +
                                            "Der Zugang zur Datei ist durch Klicken auf 'Datensätze' möglich");

                            ButtonPath.Visibility          = Visibility.Visible;
                            TextBoxPath.Text               = PmPath + "\\" + "MyPW.txt";
                            TextBoxPath.Visibility         = Visibility.Visible;
                            ButtonDataCount.Visibility     = Visibility.Visible;
                            ButtonChangeDirMain.Visibility = Visibility.Visible;
                            TextBoxPath.Background         = System.Windows.Media.Brushes.LightGreen;
                            ImagePw.Visibility             = Visibility.Visible;
                            ok = false;
                            break;
                        }
                        //else
                        //{
                        //    MessageBox.Show("Fehler bei Datensatz " + ListPw.Count, "", MessageBoxButton.OK, MessageBoxImage.Error);
                        //}
                    }
                }


                inputStream.Close();
                cStream.Close();
            }
            catch
            {
                MessageBox.Show("Ein Fehler ist aufgetreten!", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return(ok);
        }