login using store procedure and give login failed if user not already registered..

Posted by Ankitsrist under ASP.NET category on | Points: 40 | Views : 1674
hello techies,
here i will explain how to make login page nd check whether user has registered or not using store procedure...firstly make simple table by name"stuloginstoreproc " in database which has id(set as identity) name and password...and then make store procedure named "signin" as follows....
create PROCEDURE [dbo].[signin]

@name varchar(50),
@password int


SELECT * from stuloginstoreproc where @name=name and @password=password

following is the design u can make according to ur need
<%@ Page Language="C#" MasterPageFile="~/nationalmaster.master" AutoEventWireup="true" CodeFile="signin.aspx.cs" Inherits="signin" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<br />
username &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
password &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="btnsign" runat="server" OnClick="btnsign_Click" OnClientClick ="return confirm('are u sure want move')" Text="sign in" />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<asp:Label ID="lblsign" runat="server"></asp:Label><br />
<br />
new user?<br />
<a href="register.aspx">Register Here</a>

and then write code separation file as follows...means aspx.cs file

using System.Data.SqlClient;

public partial class signin : System.Web.UI.Page
dbClass db = new dbClass();
protected void Page_Load(object sender, EventArgs e)

protected void btnsign_Click(object sender, EventArgs e)
SqlCommand cmd = new SqlCommand("signin", db.sqlcon);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", SqlDbType.VarChar).Value = TextBox1.Text;
cmd.Parameters.AddWithValue("@password", SqlDbType.Int).Value = TextBox2.Text;
SqlDataReader dr = cmd.ExecuteReader ();
if (dr.HasRows)
lblsign.Text = "successfully logged in";
Session["Loginname"] = TextBox1.Text;

lblsign.Text = "login failed";


now u are done njoy

Comments or Responses

Posted by: Karthikreddy on: 2/8/2013 Level:Starter | Status: [Member] | Points: 10
thanks bro
Posted by: Ankitsrist on: 2/8/2013 Level:Starter | Status: [Member] | Points: 10
thanks karthik for ur compliements :)

Login to post response