Creating Login Or Signin Page Using .NET Framework

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

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Configuration;  
  8. //connectivity  
  9. using System.Data;  
  10. //diconnection mode  
  11. using System.Data.SqlClient;  
  12. // login time  
  13. public partial class Login : System.Web.UI.Page  
  14. {  
  15.    SqlConnection con;  
  16.    SqlCommand cmd;  
  17.    // object  
  18.    SqlDataReader dr;  
  19.    // it will read data  
  20.    int i = -1;  
  21.    // no login yet  
  22.    string id, ;  
  23.    // it will take user value  
  24.    protected void Page_Load(object sender, EventArgs e)  
  25.    {  
  26.    }  
  27.    protected void Button1_Click(object sender, EventArgs e)  
  28.    {  
  29.       Try  
  30.       {  
  31.          con = new SqlConnection(configurationManager.connectionString("ABC").connectionString);  
  32.          con.Open();  
  33.          string cmdst = "select name, word from reg where uid='" + TextBox1.Text.Trim() + "'";  
  34.          // trim removes whitespaces  
  35.          cmd = new SqlCommand(cmdst, con);  
  36.          dr = cmd.ExecuteReader();  
  37.          // help in reading data  
  38.          while (dr.Read())  
  39.          {  
  40.             id = dr[0].ToString();  
  41.              = dr[1].ToString();  
  42.          }  
  43.          if (id.Equals(TextBox1.Text.Trim()) && .Equals(TextBox1.Text.Trim()))  
  44.          {  
  45.             Session["Response"] = id;  
  46.             // creating a session  
  47.             i = 0;  
  48.             // user login  
  49.          }  
  50.       }  
  51.       catch (Exception pp)  
  52.       // exception handling  
  53.       {  
  54.       }  
  55.       finally  
  56.       // connection termination  
  57.       {  
  58.          con.Close();  
  59.          if (i == 0)  
  60.             // condition for rechecking  
  61.          {  
  62.             Response.Redirect("Profile.aspx");  
  63.          }  
  64.          Else  
  65.          {  
  66.             lblMessage.Text = "Invalid Login!";  
  67.             // label  
  68.             lblMessage.Visible = true;  
  69.             // label  
  70.          }  
  71.       }  
  72.    }  
  73. }  
 


Similar Articles