write a program to create login form



write a program to create login form..

Answer / suman

The following example demonstrates how to use a Login
control to provide a user interface to log on to a Web site
with sql server database. VB : Imports System.Data ,
Imports System.Data.SqlClient and Imports
System.Web.Configuration , C# : using System.Data; , using
System.Data.SqlClient; and using System.Web.Configuration;
1. xml file or web.config
<?xml version="1.0"?>

<configuration>

<connectionStrings>
<add name="ConnectionASPX" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwi
nd.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>

</configuration>

2. how-to-login-with-sql-server-c.aspx (Design Page)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="how-
to-login-with-sql-server-c.aspx.cs"
Inherits="how_to_login_with_sql_server_c" %>

<!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>how to login with sql server database</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Login ID="Login1" runat="server"
BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-
Names="Verdana" Font-Size="0.8em"
ForeColor="#333333"
OnAuthenticate="Login1_Authenticate" TextLayout="TextOnTop"
Width="293px"
Height="172px">
<TitleTextStyle BackColor="#990000" Font-
Bold="True" Font-Size="0.9em"
ForeColor="White" />
<InstructionTextStyle Font-Italic="True"
ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="White"
BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em"
ForeColor="#990000" />
</asp:Login>

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

3. how-to-login-with-sql-server-c.aspx.cs (Code Behind
C# Language)
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;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class how_to_login_with_sql_server_c :
System.Web.UI.Page
{
protected void Login1_Authenticate(object sender,
AuthenticateEventArgs e)
{
string username = Login1.UserName;
string pwd = Login1.Password;

string strConn;
strConn = WebConfigurationManager.ConnectionStrings
["ConnectionASPX"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();

string sqlUserName;
sqlUserName = "SELECT UserName,Password FROM
UserName ";
sqlUserName += " WHERE (UserName ='" + username
+ "')";
sqlUserName += " AND (Password ='" + pwd + "')";
SqlCommand com = new SqlCommand(sqlUserName, Conn);

string CurrentName;
CurrentName = (string)com.ExecuteScalar();

if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("how-to-StartPage.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
}

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More Dot Net WindowsForms Interview Questions

What are the new events in textbox that has been included in VB ?

2 Answers  


Which property of the progressbar control specifies the amount to increment the current value of the control?

0 Answers  


What are the properties of datacontrol?

0 Answers   HCL,


Clear property is available in which control?

5 Answers  


Are windows forms still used?

0 Answers  






Which of the following position is the default docking position of the statusstrip control on the form?

0 Answers  


what are the differences between image and picture controls?

1 Answers  


How many system controls are available ?

1 Answers  


What is the use of runworkasync() methods?

0 Answers  


What are window applications?

0 Answers  


Explain the new events in textbox that has been included in vb?

0 Answers  


Name the event that enables the user to prevent shifting of focus from control until all the validation rules have been met.

0 Answers  


Categories