login.aspx
<asp:Panel ID="panel1" runat="server">
<table>
<tr>
<td align="right">
<asp:Label ID="lblUid" runat="server" Text="UserName :"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtUid" runat="server" Height="25px" Width="275px" BorderColor="#666666"
BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvlogin" runat="server" Display="Dynamic" ControlToValidate="txtUid"
Text="*" CssClass="err" ValidationGroup="l" />
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="lblpwd" runat="server" Text="Password :"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password" Height="25px" Width="275px"
BorderColor="#666666" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ControlToValidate="txtpwd" CssClass="err" ValidationGroup="l" Text="*" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Sign In"
ValidationGroup="l" Height="30px" Width="90px" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Forgot Login Details? <asp:HyperLink ID="hlnkForgottenPassword" runat="server"
NavigateUrl="~/ForgotPassword.aspx">Click Here</asp:HyperLink>
</td>
</tr>
</table>
</asp:Panel>
<br />
<br />
<asp:Label ID="ltrmsg" runat="server" ForeColor="Red" /></p>
login.asp.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
public partial class Login : System.Web.UI.Page
{
BAL bal = new BAL();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (txtUid.Text != null && txtpwd.Text != null)
{
if (bal.getUserLoginDetails(txtUid.Text, txtpwd.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUid.Text, false);
Session["UserId"] = txtUid.Text;
Response.Redirect("~/User/Welcome.aspx");
}
else
ltrmsg.Text = "Invalid Username (or) Password.";
}
else
ltrmsg.Text = "Username & Password cann't be empty";
}
catch (Exception ex)
{
ltrmsg.Text = ex.Message;
}
}
}
BAL.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for BAL
/// </summary>
public class BAL
{
DAL dal = new DAL();
DataSet ds = new DataSet();
public BAL()
{
//
// TODO: Add constructor logic here
//
}
public bool getUserLoginDetails(string Uid, string pwd)
{
try
{
string _sql = "Sp_UserLoginDetails";
SqlParameter[] par = new SqlParameter[2];
par[0] = new SqlParameter("@uid", Uid);
par[1] = new SqlParameter("@pwd", pwd);
if (dal.getLoginDetails(_sql, par))
return true;
else
return false;
// string _sql = "SELECT Username FROM TblUserRegistration where Username='" + Uid + "' AND Password='" + pwd + "'";
// if (dal.getLoginDetails(_sql))
// return true;
// else
// return false;
}
catch (Exception ex)
{
throw ex;
}
}
}
DAL.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
SqlConnection con;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd;
string fname;
public DAL()
{
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["class"].ToString());
fname = string.Empty;
}
public bool getLoginDetails(string _sql, SqlParameter[] sqlparam)
{
try
{
string Uid;
con.Open();
cmd = new SqlCommand(_sql, con);
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter p in sqlparam)
{
cmd.Parameters.Add(p);
}
Uid = Convert.ToString(cmd.ExecuteScalar());
if (Uid.Length > 0)
{
return true;
}
else
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
}
<table>
<tr>
<td align="right">
<asp:Label ID="lblUid" runat="server" Text="UserName :"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtUid" runat="server" Height="25px" Width="275px" BorderColor="#666666"
BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvlogin" runat="server" Display="Dynamic" ControlToValidate="txtUid"
Text="*" CssClass="err" ValidationGroup="l" />
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="lblpwd" runat="server" Text="Password :"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtpwd" runat="server" TextMode="Password" Height="25px" Width="275px"
BorderColor="#666666" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ControlToValidate="txtpwd" CssClass="err" ValidationGroup="l" Text="*" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Sign In"
ValidationGroup="l" Height="30px" Width="90px" />
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Forgot Login Details? <asp:HyperLink ID="hlnkForgottenPassword" runat="server"
NavigateUrl="~/ForgotPassword.aspx">Click Here</asp:HyperLink>
</td>
</tr>
</table>
</asp:Panel>
<br />
<br />
<asp:Label ID="ltrmsg" runat="server" ForeColor="Red" /></p>
login.asp.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
public partial class Login : System.Web.UI.Page
{
BAL bal = new BAL();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (txtUid.Text != null && txtpwd.Text != null)
{
if (bal.getUserLoginDetails(txtUid.Text, txtpwd.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUid.Text, false);
Session["UserId"] = txtUid.Text;
Response.Redirect("~/User/Welcome.aspx");
}
else
ltrmsg.Text = "Invalid Username (or) Password.";
}
else
ltrmsg.Text = "Username & Password cann't be empty";
}
catch (Exception ex)
{
ltrmsg.Text = ex.Message;
}
}
}
BAL.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for BAL
/// </summary>
public class BAL
{
DAL dal = new DAL();
DataSet ds = new DataSet();
public BAL()
{
//
// TODO: Add constructor logic here
//
}
public bool getUserLoginDetails(string Uid, string pwd)
{
try
{
string _sql = "Sp_UserLoginDetails";
SqlParameter[] par = new SqlParameter[2];
par[0] = new SqlParameter("@uid", Uid);
par[1] = new SqlParameter("@pwd", pwd);
if (dal.getLoginDetails(_sql, par))
return true;
else
return false;
// string _sql = "SELECT Username FROM TblUserRegistration where Username='" + Uid + "' AND Password='" + pwd + "'";
// if (dal.getLoginDetails(_sql))
// return true;
// else
// return false;
}
catch (Exception ex)
{
throw ex;
}
}
}
DAL.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
SqlConnection con;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlCommand cmd;
string fname;
public DAL()
{
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["class"].ToString());
fname = string.Empty;
}
public bool getLoginDetails(string _sql, SqlParameter[] sqlparam)
{
try
{
string Uid;
con.Open();
cmd = new SqlCommand(_sql, con);
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter p in sqlparam)
{
cmd.Parameters.Add(p);
}
Uid = Convert.ToString(cmd.ExecuteScalar());
if (Uid.Length > 0)
{
return true;
}
else
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
}
No comments:
Post a Comment