Login page using 3-Tier Architecture in ASP.Net

This tutorial explains how to implement a Login page using 3-Tier Architecture in ASP.Net. I have described it in details. You will also get many new and known concepts to learn in this article whether on the SQL Server Query or C# code side.

In previous tutorial we have learn How to create a login page using asp.net mvc

Step :1  Open visual studio and create asp.net web project then create the sql server database with login table.in login table add field name and password

Step :2  Now you can add class DAL.CS  this class is known as first tier means it is data access layer

public class DAL
{
public int id { get; set; }
public string name { get; set; }
public string password { get; set; }
public string city { get; set; }

}

Step 3 :  Now you can add another Class BAL.CS this class known as Logical layer, here we can write the business query for for check login name and password is correct or not

public class BAL
{
SqlConnection con = new SqlConnection(@”Data Source=.\SQ;User Instance=True”);

public DataTable login_data(DAL da)
{
DataTable dt = new DataTable();

SqlDataAdapter sda = new SqlDataAdapter(“select * from user_master where name='” + da.name + “‘and password='” + da.password + “‘”, con);

sda.Fill(dt);

return dt;
}

Step 4 :  Now you can Add WebForm and Give name SignIn.aspx  then add two TextBox and Submit Button & add Code in CodeBehind file.

public partial class SignIn : System.Web.UI.Page
{
DAL da = new DAL();
BAL ba = new BAL();
DataTable dt=new DataTable();
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
da.name = TextBox1.Text;
da.password = TextBox2.Text;
dt = ba.login_data(da);
if (dt.Rows.Count > 0)
{
Response.Redirect(“home.aspx”);
}
else
{
Response.Write(“<script>alert(‘Not Valid User…….’)</script>”);
}
}

When you enter user name and password in Textbox & if user name and password are correct then it redirect to Home.aspx page if name & password are incorrect it display alert massage “Not Valid User…….“.

Login page using 3-Tier Architecture in ASP.Net

SEE MORE