Thursday, March 3, 2011

Login Control

Here is the code for manually handling the login control

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
DataSet userlogins = new DataSet();
userlogins.ReadXml(MapPath("logins.xml"));

foreach (DataRow row in userlogins.Tables[0].Rows)
{
Response.Write(row["username"].ToString() + " " + row["password"].ToString());

if (row["username"].ToString()==(Login1.UserName)
&& row["password"].ToString()==(Login1.Password))
{
e.Authenticated = true;
Response.Redirect("Default2.aspx");
return;
}
else
{
e.Authenticated = false;
}

}
}
}

No comments:

Post a Comment