public void AddItem(string desc, string user, string pass, string date, string log, string acc) { XmlElement account = _doc.CreateElement("account"); account.SetAttribute("user-id", user); XmlElement description = _doc.CreateElement("description"); description.InnerText = desc; account.AppendChild(description); XmlElement password = _doc.CreateElement("password"); _SetStrength(pass); password.InnerText = pass; password.SetAttribute("strength", StrengthLabel); password.SetAttribute("percentage", StrengthPercent.ToString()); //var today = DateTime.Now; //string xmlDate = today.Year + "-"; //if (today.Month < 10) //{ // xmlDate += "0" + today.Month + "-"; //} //else //{ // xmlDate += today.Month + "-"; //} //if (today.Day < 10) //{ // xmlDate += "0" + today.Day + "-"; //} //else //{ // xmlDate += today.Day; //} password.SetAttribute("date", date); account.AppendChild(password); XmlElement loginURLElement = _doc.CreateElement("login-url"); loginURLElement.InnerText = log; account.AppendChild(loginURLElement); XmlElement accountElement = _doc.CreateElement("account-number"); accountElement.InnerText = acc; account.AppendChild(accountElement); _doc.DocumentElement.FirstChild.AppendChild(account); }
public void ChangePassword(int index) { Console.Write("New Password:"******"account"); XmlElement accountElement = account[index - 1] as XmlElement; //get selected element password tag var passwords = accountElement.GetElementsByTagName("password"); XmlElement passwordElement = passwords[0] as XmlElement; //run password helper _SetStrength(password); passwordElement.InnerText = password; passwordElement.SetAttribute("strength", StrengthLabel); passwordElement.SetAttribute("percentage", StrengthPercent.ToString()); //easy way //string xmlDate = DateTime.Now.ToString("yyyy-MM-dd"); //change date var today = DateTime.Now; string xmlDate = today.Year + "-"; if (today.Month < 10) { xmlDate += "0" + today.Month + "-"; } else { xmlDate += today.Month + "-"; } if (today.Day < 10) { xmlDate += "0" + today.Day + "-"; } else { xmlDate += today.Day; } passwordElement.SetAttribute("date", xmlDate); }