IN THIS ARTICLE YOU WILL LEARN HOW MAKE LOGIN STORE PROCEDURE WITH USE OF ASP.NET(C SHARP) OR LOGIN PAGE FOR YOUR SITE

STEP 1: MAKE A  NEW WEB SITE AND GIVE HIM NAME AS YOU WISH

STEP 2: NOW MAKE A NEW DATABASE IF YOU HAVE OLD DATABSE THEN THAT ALSO GOOD AND MAKE A NEW TABLE IN THAT DATABASE WHOSE NAME WILL BE tbl_User AS GIVE BELOW IN PICTURE

Table Structure is Given Below

COLUMN NAME                 DATATYPES

intId                                        int

strUserId                                                varchar(25)

strUserPass                            varchar(25)

chrUserRole                          char(1)

btIsActive                               bit

dtDateTime                           datetime

Note: Remember to set Identity true of intId Column and Also Set Primary Key

STEP 3: NOW ENTER SOME DUMMY ENTRIES IN YOUR TABLE AS GIVEN BELOW

STEP 4: Place Controls On Your Login.aspx Page As Given Below In picture

STEP 5: Now Double Click On page and Make  Connectivity Of Your Web Site with SqlServer2005

//How to Make Connection with Sql Database On page Load

SqlConnection con = new SqlConnection();

protected void Page_Load(object sender, EventArgs e)

{

con.ConnectionString = ConfigurationManager.ConnectionStrings[“cn”].ConnectionString;

if (con.State == ConnectionState.Closed)

{

con.Open();

}

}

For Testing of Your Connectivity Set as Start page of Your login.aspx page and run or compile your website by pressing F5 button.

If Successfully Run then it means your connection has been established.

FOR MORE CLARITY OF YOUR PRACTICAL PICTURES ARE GIVEN BELOW.

When You Will Compile Your Web Site for connection testing Then A Popup window will show this message you just click on ok

Step 6: Now Make a Function For Login Check As Given Below

public Int32 CheckUsr(String UserName, String UserPass,out String Status)

{

if (con.State == ConnectionState.Closed)

{

con.Open();

}

SqlCommand cmdObj = new SqlCommand(“Proc_CheckUser”, con);

cmdObj.CommandType = CommandType.StoredProcedure;

cmdObj.Parameters.AddWithValue(“@strUserId”, TextBox1.Text);

cmdObj.Parameters.AddWithValue(“@strUserPass”, TextBox2.Text);

cmdObj.Parameters.Add(“@intUserId”,SqlDbType.Int).Direction = ParameterDirection.Output;

cmdObj.Parameters.Add(“@chrUserRol”,SqlDbType.Char,1).Direction = ParameterDirection.Output;

cmdObj.ExecuteNonQuery();

Status = cmdObj.Parameters[“@chrUserRol”].Value.ToString();

Int32 Orient = Convert.ToInt32(cmdObj.Parameters[“@intUserId”].Value);

return Orient;

}

STEP 7:Now Make a Store procedure for Login Check Which Will accept your pass values and Check it out that user is valid for logging or not

ALTER PROCEDURE Proc_CheckUser

(

@strUserId varchar(25),

@strUserPass varchar(25),

@intUserId int output,

@chrUserRol char(1) output

)

AS

DECLARE @ActualPass VARCHAR(50)

DECLARE @bit VARCHAR(10)

–this query will put password of user into variable

SELECT @ActualPass=strUserPass ,@bit=btIsActive FROM tbl_User WHERE strUserId=@strUserId

–check of user password is null or not

IF @ActualPass IS NOT NULL AND      @ActualPass=@strUserPass AND @bit=’1′

BEGIN

SET @intUserId=1

SELECT @chrUserRol=chrUserRole FROM tbl_User WHERE strUserId=@strUserId

END

ELSE IF @ActualPass !=@strUserPass

BEGIN

SET @intUserId=-2

SET @chrUserRol=’N’

END

ELSE

BEGIN

SET @intUserId= -1

SET @chrUserRol=’N’

END

Which store procedures  is defined in this picture that’s without IsActive Column

STEP 8: Now Add New Pages  By right click on WebSite menu and click in it Add New Item submenu or You can do this by short command (Ctrl+Shift+A)In your Web Site And Given Them Name Admin.aspx,Employee.aspx,Client.aspx,Member.aspx.

The step of adding new page is given in Pic.

STEP 9: NOW  CALL METHOD ON BUTTON CLICK AS GIVEN BELOW

/// <summary>
/// here A Stands for Admin
/// E stands for Employee
/// M stands for Memember
/// C stands for Client
/// </summary>
protected void Button1_Click(object sender, EventArgs e)
{
String OutStatus = string.Empty;
Int32 getStoreOutput=CheckUsr(TextBox1.Text, TextBox2.Text,out OutStatus);
if (getStoreOutput > 0)
{
if (OutStatus == “A”)
{
Response.Redirect(“Admin.aspx”);
}
else if (OutStatus == “E”)
{
Response.Redirect(“Employee.aspx”);
}
else if (OutStatus == “M”)
{
Response.Redirect(“Member.aspx”);
}
else if (OutStatus == “C”)
{
Response.Redirect(“Client.aspx”);
}
else if (OutStatus == “N”)
{
Response.Redirect(“Error.aspx”);
}
else
{
Response.Write(“You Are Triying Forcefully logging in out site!!!”);
}
}
else if (getStoreOutput == -1)
{
Response.Write(“User Name Is Wrong”);
}
else
{
Response.Write(“Password Is Wrong”);
}
}
step 10 : RUN YOUR WEB SITE BY PRESSING F5 AND ENTER VALUES INTO TEXT BOX AS GIVEN BELOW
Enjoy and Be Happy!!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s