Create Login Page with 3 Tier Architecture


Create Login Page with 3 tier architecture

In this articles i'm going to show you how to create login page with 3 tier architecture by using asp.net c# coding. First we need to design asp.net page as i shown in above images simply copy and paste the below html and css code for designing purpose.



Create Login Page :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

---------   ADD CSS CODE HERE    ----------

</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:TextBox ID="txtusername" CssClass="textbox_username textbox" runat="server" placeholder="Username"></asp:TextBox><br /><br />
     <asp:TextBox ID="txtpassword" CssClass="textbox_pwd textbox" runat="server" placeholder="Password"></asp:TextBox><br /><br />
     <asp:Button ID="Btn_Login" CssClass="Button" runat="server" Text="Login" />
    </div>
    </form>
</body>
</html>
CSS Code :

 
 
C# Code : Login Button Click :

 private void Btn_Logic_Click(object sender, EventArgs e)
  {
   BusinessAccessLayer.BusinessLogic bl = new BusinessAccessLayer.BusinessLogic();
   bool result;
   result = bl.IsValidUser(textBox1.Text, textBox2.Text);
   if (result == true)
   MessageBox.Show("Successfully Logged in!");
 else
   MessageBox.Show("Invalid Login");
  }



DataAccessLayer :

  1. Add Class File and rename class1.cs into Databaselogic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
 namespace DataAccessLayer
  {
   public class DatabaseLogic
    {
     public DataTable GetUsers(string Username, string Password)
      {
        //connection logic
       string cnstr = ConfigurationSettings.AppSettings["RemoteDatabase"];
       SqlConnection cn = new SqlConnection(cnstr);
       //stmt logic
       string sqlstr = "select * from users where username= ' " + Username + " ' and password= ' " + Password + " ' ";
       //adapter logic
       SqlDataAdapter adp = new SqlDataAdapter(sqlstr, cn);
       DataSet ds = new DataSet();
       adp.Fill(ds);
       //datatable logic
       DataTable dt;
       dt = ds.Tables[0];
       return (dt);
      }
    }
  } 

BusinessAccessLayer :

  1. Add Class file and rename class1.cs into BusinessLogic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
 namespace BusinessAccessLayer
  {
   public class BusinessLogic
   {
    public bool IsValidUser(string Username, string Password)
     {
      DataTable dt;
      DataAccessLayer.DatabaseLogic dbl = new DataAccessLayer.DatabaseLogic();
      dt = dbl.GetUsers(Username, Password);
      if (dt.Rows.Count > 0)
      return true;
    else
      return false;
     }
   }
 } 


Tag : ASP.NET
0 Komentar untuk "Create Login Page with 3 Tier Architecture"

Back To Top