How to do a login page by using login control [Resolved]

Posted by Kundan under ASP.NET on 8/21/2013 | Points: 10 | Views : 777 | Status : [Member] | Replies : 1
How to do a login page by using login control in asp.net




Responses

Posted by: Satyapriyanayak on: 8/21/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Login._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:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate"
DestinationPageUrl="~/Home.aspx" BackColor="#FFFBD6" BorderColor="#FFDFAD"
BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#333333" TextLayout="TextOnTop">
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TitleTextStyle BackColor="#990000" Font-Bold="True" Font-Size="0.9em"
ForeColor="White" />
</asp:Login>
</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
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{

str = "select * from users where UserName='" + Login1.UserName.ToString() + "' and password='" + Login1.Password.ToString() + "'";
using (SqlConnection conn = new SqlConnection(connStr))
{
ds = new DataSet();
sqlda = new SqlDataAdapter();
conn.Open();
com = new SqlCommand(str, conn);
com.ExecuteNonQuery();
sqlda.SelectCommand = com;
sqlda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
conn.Close();
Response.Redirect("Home.aspx");
}
else
{
return;
}
}
}
}
}


If this post helps you mark it as answer
Thanks

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response