Reader Level:
ARTICLE

Creating Login Or Signin Page Using .NET Framework

Posted by Abhishek Jaiswal Articles | ASP.NET Programming February 08, 2014
Here we learn how to create a Login or Signin page using the .NET Framework.
  • 1
  • 0
  • 5917

Creating a Login or Signin page is a very interesting part of any website or portal, user login or database access. Generally this happens at the backend depending on the type of your database and a connecting tool.

I am using Microsoft SQL Server for the database and Microsoft Visual Studio as the IDE.

The procedure for doing this is explained below in a simple and compact way, here we go.

Basically all these steps occurs in the backend, except a very few.

Step 1: Connectivity

In the very first step the database connectivity occurs and this step creates a link or an interface between the database and your domain, through which the data can be accessed easily anytime without any distinction.

Backend Process

The sub steps involved in it are:



Step 2: Database Access


After establishing a link between the database and your domain tool, now the data will be accessed depending on the use or priority of the end user.

Backend Process

This step has these sub steps under it:



Step 3: User Session

The detail view of the user session and all the major and minor details I have already mentioned in my previous article.

(So I want you to have a look at that article before proceeding further, because that article will give you a precise description of the view of the session process along with maintenance and other details.)

Backend Process

  • Session
  • Maintenance

Step 4: Procedure

The the user session will get in the race. The next steps will join them. Some of these procedural steps occur due to end user activity like a Click event (on button press) or we can say that this occurs when a user clicks on a button for the purpose of logging in or signing in into an already registered account.

(Initiated at the front end by a click event and the other steps follow it at the backend afterwards.)

The sub steps under this procedural step are as follows.



Step 5: Finish

This is the final backend process. Under this process there are also two steps to be done, these steps are:



Under Response there are still two possibilities that can happen, they are:

  • Login
  • Invalid Login

Functioning | Example Code

Under this you need to only code in the .cs file, for that open Visual Studio, then follow the procedure as I described In the previous article, maintaining user session.

(Follow the procedure in that article.)

Code here: (in .CS file)



Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
//connectivity
using System.Data;
//diconnection mode
using System.Data.SqlClient;
// login time
public partial class Login : System.Web.UI.Page
{
   SqlConnection con;
   SqlCommand cmd;
   // object
   SqlDataReader dr;
   // it will read data
   int i = -1;
   // no login yet
   string id, pass;
   // it will take user value
   protected void Page_Load(object sender, EventArgs e)
   {
   }
   protected void Button1_Click(object sender, EventArgs e)
   {
      Try
      {
         con = new SqlConnection(configurationManager.connectionString("ABC").connectionString);
         con.Open();
         string cmdst = "select name, password from reg where uid='" + TextBox1.Text.Trim() + "'";
         // trim removes whitespaces
         cmd = new SqlCommand(cmdst, con);
         dr = cmd.ExecuteReader();
         // help in reading data
         while (dr.Read())
         {
            id = dr[0].ToString();
            pass = dr[1].ToString();
         }
         if (id.Equals(TextBox1.Text.Trim()) && pass.Equals(TextBox1.Text.Trim()))
         {
            Session["Response"] = id;
            // creating a session
            i = 0;
            // user login
         }
      }
      catch (Exception pp)
      // exception handling
      {
      }
      finally
      // connection termination
      {
         con.Close();
         if (i == 0)
            // condition for rechecking
         {
            Response.Redirect("Profile.aspx");
         }
         Else
         {
            lblMessage.Text = "Invalid Login!";
            // label
            lblMessage.Visible = true;
            // label
         }
      }
   }

COMMENT USING