Search Asp.Net Here

Authentication using XML




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



Comments :

2 comments to “Authentication using XML”
கருப்பையா said...
on 

try XPath or LINQ which will make this run faster. This will work but will not scale when your xml size is huge

Anonymous said...
on 

Hi Dear,
I don't have access in IIS.
But I want to add a role based functionality in asp.net application ?
Is it possible without IIS ?
If yes How I will do this ?

Thanks.

Post a Comment