Login Page Using parameter in asp.net

Satyapriyanayak
Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 1056
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="login_using_parameter._Default" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text="Name" Font-Bold="True"
Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True"
Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600"
TextMode="Password" Width="100px"></asp:TextBox><br />
<asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True"
BackColor="#CCFF99" onclick="btn_login_Click" /><br />
</div>

</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace login_using_parameter
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str = null;
SqlCommand com;

protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from login where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@UserName", TextBox_user_name.Text);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
lb1.Text = "WELLCOME :: " + TextBox_user_name.Text;
}
else
{
lb1.Text = "invalid user name and password";
}
con.Close();
}
}
}

Comments or Responses

Login to post response