Authentication using xml


how to authenticate users using xml file

How to make users in XML File and authenticate them..
Solution:
create a xml file as

 


<mydata>
<tb>
<user>admin</user>
<pass>admin</pass>
</tb>
<tb>
<user>admin1</user>
<pass>admin1</pass>
<tb>
<tb>
<user>admin2</user>
<pass>admin2</pass>
<tb>
</mydata>





Add two Text Boxes on Design page with ids TextBox1 and TextBox2

Add a label with id Label1
Add a button
double click on button
and write following code in button click event

 

//code to authenticate user
String pt = Server.MapPath("XMLFile.xml");//
DataSet ds = new DataSet();
ds.ReadXml(pt);
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "user='" + TextBox1.Text+"'";
if (dv.Count == 0)
Label1.Text = "Wrong User";
else
{
if (dv[0][1].ToString() == TextBox2.Text)
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
else
Label1.Text = "Wrong Password";
}




Run the application

Reference: howinaspnet.blogspot.com


Related Articles

Impersonation

User who is responsible for running current thread can be impersonated programmatically.

More articles: Authentication XML Impersonation Authentication Authorization

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: