C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Storing login information in XML file


Posted Date: 09 Oct 2008    Resource Type: Code Snippets    Category: ADO.NET

Posted By: Dharmaraj       Member Level: Diamond
Rating:     Points: 10



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;
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Saving login information in XML file  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Grid Demo
Previous Resource: Insering Values in to Database
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

teleconferencing

Contact Us    Privacy Policy    Terms Of Use