This code describes how to store login information in XML File
//Pass the Values from the Textbox to this function public static string SaveCredentials(string userName, string passWord, string passwordConfirm, bool updatePassword) { string statusMessage=""; if (! System.IO.File.Exists(HttpContext.Current.Server.MapPath("Users.xml"))) System.IO.File.Create(HttpContext.Current.Server.MapPath("Users.xml")); DataSet loginDS = new DataSet(); //Read the Xml File loginDS.ReadXml(HttpContext.Current.Server.MapPath("Users.xml"));
loginDS.Tables[0].DefaultView.RowFilter="username='" + userName + "'";
if (passWord != "" && passWord == passwordConfirm) { DataRow newLogin = loginDS.Tables[0].NewRow(); newLogin["username"] = userName; newLogin["password"] = FormsAuthentication.HashPasswordForStoringInConfigFile(passWord,"MD5"); newLogin["registerdate"] = DateTime.Today.ToShortDateString(); loginDS.Tables[0].Rows.Add(newLogin); loginDS.WriteXml(HttpContext.Current.Server.MapPath("Users.xml")); statusMessage = "Registration succeded. Please log in."; } else { statusMessage = "No password entered " + "or passwords do not match. Please re-enter."; } if (updatePassword) { DataRow newLogin = loginDS.Tables[0].NewRow(); newLogin["username"] = userName; newLogin["password"] = FormsAuthentication.HashPasswordForStoringInConfigFile(passWord,"MD5"); newLogin["registerdate"] = DateTime.Today.ToShortDateString(); loginDS.Tables[0].Rows.Add(newLogin); loginDS.WriteXml(HttpContext.Current.Server.MapPath("Users.xml")); statusMessage = "Password Updated";
}
else { statusMessage = "An identical username exists. Please choose another."; } return statusMessage; }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|