예제 #1
0
        public static List <Pwd> fromXml(string content)
        {
            TextReader xmlfs = new StringReader(content);
            XmlReader  xmlr  = XmlReader.Create(xmlfs);

            List <Pwd> loaded = new List <Pwd>();

            Pwd          current = null;
            List <float> cpoints = new List <float>();

            while (xmlr.Read())
            {
                if (xmlr.Name == "Pwd" && xmlr.NodeType == XmlNodeType.Element)
                {
                    current = new Pwd("", "", DateTime.Now, "", "", "", "");
                    cpoints = new List <float>();
                }
                else if (xmlr.Name == "item" && xmlr.NodeType == XmlNodeType.Element)
                {
                    string nodekey    = xmlr.GetAttribute("key");
                    var    properties = current.GetType().GetProperties();
                    Type   ptype      = current.GetType().GetProperty(nodekey).PropertyType;
                    current.GetType().GetProperty(nodekey).SetValue(current, Convert.ChangeType(xmlr.ReadElementContentAsString(), ptype), null);
                }
                else if (xmlr.Name == "Pwd" && xmlr.NodeType == XmlNodeType.EndElement)
                {
                    loaded.Add(current);
                }
            }
            xmlfs.Close();
            return(loaded);
        }
예제 #2
0
 // Save a new or edited entry
 private void button1_Click(object sender, EventArgs e)
 {
     if (edit)
     {
         int key = Convert.ToInt32(dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[5].Value);
         Program.passwords.Find(Pwd => Pwd.KEY == key).nameSpace = textBox_name.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).datetime = dateTimePicker_date.Value;
         Program.passwords.Find(Pwd => Pwd.KEY == key).category = textBox_category.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).username = textBox_username.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).email = textBox_email.Text;
     }
     else
     {
         Pwd pwd = new Pwd(textBox_name.Text, textBox_category.Text, dateTimePicker_date.Value, textBox_username.Text, textBox_email.Text, textBox_password.Text, textBox_notes.Text);
         pwd.KEY = Program.IDENTIFIER;
         Program.IDENTIFIER++;
         Program.passwords.Add(pwd);
         updateList();
     }
 }
예제 #3
0
 // Save a new or edited entry
 private void button1_Click(object sender, EventArgs e)
 {
     if (edit)
     {
         int key = Convert.ToInt32(dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[5].Value);
         Program.passwords.Find(Pwd => Pwd.KEY == key).nameSpace = textBox_name.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).datetime  = dateTimePicker_date.Value;
         Program.passwords.Find(Pwd => Pwd.KEY == key).category  = textBox_category.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).username  = textBox_username.Text;
         Program.passwords.Find(Pwd => Pwd.KEY == key).email     = textBox_email.Text;
     }
     else
     {
         Pwd pwd = new Pwd(textBox_name.Text, textBox_category.Text, dateTimePicker_date.Value, textBox_username.Text, textBox_email.Text, textBox_password.Text, textBox_notes.Text);
         pwd.KEY = Program.IDENTIFIER;
         Program.IDENTIFIER++;
         Program.passwords.Add(pwd);
         updateList();
     }
 }
예제 #4
0
        public static string toXml(Pwd pwd)
        {
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("nameSpace", pwd.nameSpace);
            data.Add("category", pwd.category);
            data.Add("datetime", pwd.datetime);
            data.Add("username", pwd.username);
            data.Add("email", pwd.email);
            data.Add("password", pwd.password);
            data.Add("notes", pwd.notes);

            StringBuilder xml = new StringBuilder();

            xml.AppendLine(" <Pwd>");
            foreach (KeyValuePair <string, object> item in data)
            {
                xml.AppendLine(String.Format("  <item key=\"{0}\">{1}</item>", item.Key, item.Value.ToString()));
            }
            xml.AppendLine(" </Pwd>");
            return(xml.ToString());
        }
예제 #5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Create the nessecary files/folders
            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }
            if (!File.Exists(saveFile))
            {
                File.WriteAllText(saveFile, "");
            }


            while (Program.RUN)
            {
                PromptPwd pp = new PromptPwd();
                if (pp.ShowDialog() == DialogResult.OK)
                {
                    Program.KEY = pp.key;
                    bool run = true;
                    // Loading data
                    string fdata = File.ReadAllText(Program.saveFile);
                    if (Program.KEY == "" || Program.KEY == null)
                    {
                        fdata = "";
                        run   = false;
                    }
                    try
                    {
                        if (fdata != "")
                        {
                            string     DATA = Pwd.DecryptStringAES(fdata, Program.KEY);
                            List <Pwd> tmp  = Pwd.fromXml(DATA);
                            foreach (Pwd p in tmp)
                            {
                                p.KEY = Program.IDENTIFIER;
                                Program.passwords.Add(p);
                                Program.IDENTIFIER++;
                            }
                            DATA = null;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Incorrect password!");
                        run = false;
                    }

                    if (run)
                    {
                        Application.Run(new Form1());

                        // Saving data
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("<DECRYPTED_PASSWORDS>");
                        foreach (Pwd p in passwords)
                        {
                            sb.AppendLine(Pwd.toXml(p));
                        }
                        sb.AppendLine("</DECRYPTED_PASSWORDS>");
                        string EDATA = Pwd.EncryptStringAES(sb.ToString(), Program.KEY);
                        File.WriteAllText(Program.saveFile, EDATA);
                        KEY        = null;
                        sb         = null;
                        passwords  = new List <Pwd>();
                        IDENTIFIER = 0;
                    }
                }
                else
                {
                    Program.RUN = false;
                }
            }
        }
예제 #6
0
        public static string toXml(Pwd pwd)
        {
            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("nameSpace", pwd.nameSpace);
            data.Add("category", pwd.category);
            data.Add("datetime", pwd.datetime);
            data.Add("username", pwd.username);
            data.Add("email", pwd.email);
            data.Add("password", pwd.password);
            data.Add("notes", pwd.notes);

            StringBuilder xml = new StringBuilder();
            xml.AppendLine(" <Pwd>");
            foreach (KeyValuePair<string, object> item in data)
            {
                xml.AppendLine(String.Format("  <item key=\"{0}\">{1}</item>", item.Key, item.Value.ToString()));
            }
            xml.AppendLine(" </Pwd>");
            return xml.ToString();
        }
예제 #7
0
        public static List<Pwd> fromXml(string content)
        {
            TextReader xmlfs = new StringReader(content);
            XmlReader xmlr = XmlReader.Create(xmlfs);

            List<Pwd> loaded = new List<Pwd>();

            Pwd current = null;
            List<float> cpoints = new List<float>();

            while (xmlr.Read())
            {
                if (xmlr.Name == "Pwd" && xmlr.NodeType == XmlNodeType.Element)
                {
                    current = new Pwd("", "",DateTime.Now,"","","","");
                    cpoints = new List<float>();
                }
                else if (xmlr.Name == "item" && xmlr.NodeType == XmlNodeType.Element)
                {
                    string nodekey = xmlr.GetAttribute("key");
                    var properties = current.GetType().GetProperties();
                    Type ptype = current.GetType().GetProperty(nodekey).PropertyType;
                    current.GetType().GetProperty(nodekey).SetValue(current, Convert.ChangeType(xmlr.ReadElementContentAsString(), ptype), null);
                }
                else if (xmlr.Name == "Pwd" && xmlr.NodeType == XmlNodeType.EndElement)
                {
                    loaded.Add(current);
                }
            }
            xmlfs.Close();
            return loaded;
        }