Hi,
I'm writing a web application using .NET and C# that uses an Xml file for username and password storage. I need the password to be entered first then checked against the Xml file which redirects to the account page; this part of it works. The problem is on the account page, I can't figure out how to read the next set of nodes that tell the page what information to load. Right now I'm trying to get a label to display the first name of the user but it won't work.
Here is my Xml file, I exported a table from Microsoft Access 2013.
<?xml version="1.0" encoding="UTF-8"?><dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2014-04-29T12:39:37"><Staff><IdCode>0200</IdCode><FirstName>John</FirstName><LastName>Doe</LastName></Staff><Staff><IdCode>0100</IdCode><FirstName>Jane</FirstName><LastName>Doe</LastName></Staff></dataroot>
And here is the working code, where the page checks the user's password against the Xml file data.
public partial class LoginInput : System.Web.UI.Page { public string password; public string CurrentPassword = ""; protected void Page_Load(object sender, EventArgs e) { } protected void BtnLogin_Click(object sender, EventArgs e) { bool loginStatus = false; password = userInputTextBox.Text; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Server.MapPath("Staff.xml")); XmlNodeList xmlnodelist = xmldoc.GetElementsByTagName("Staff"); foreach (XmlNode xn in xmlnodelist) { XmlNodeList xmlnl = xn.ChildNodes; foreach (XmlNode xmln in xmlnl) { if (xmln.Name == "IdCode") { if (xmln.InnerText == password) { CurrentPassword = password; } } } if (CurrentPassword != "") { loginStatus = true; } } if (loginStatus == true) { Session["PasswordAuthentication"] = password; Session.Timeout = 1; Response.Redirect("StaffAccountScreen.aspx?passwordValue=" + password); } else { Session["PasswordAuthentication"] = ""; Response.Redirect("LoginError.aspx"); } } } }
I've tried doing the same thing with the account page but it always skips over the if statement where I try to find the "FirstName" tag. I pass the password value to the account page and then the page is supposed to check for the IdCode node again then find the corresponding nodes that have the first and last name and display them in a label.
Thanks for any help or suggestions.