login page code

Posted by Suneel161 under Regular Expressions on 2/3/2010 | Views : 5751 | Status : [Member] | Replies : 5
hii

i want login page code using asp 3.5,c#,sqlserver 2005.... retrieving username and password from database....plz help mee




Responses

Posted by: Abhi2434 on: 2/3/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Why you require the code. Code depends on how your database structure is.

I recommend to use <asp:login> control and create your data access code yourself.

I am sure it will help you.
Cheers

www.abhisheksur.com

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

Posted by: Sagarp on: 2/3/2010 [Member] Bronze

Up
0
Down
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class how_to_login_with_sql_server
Inherits System.Web.UI.Page

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim username As String
Dim pwd As String
Dim pName As String

username = Login1.UserName
pwd = Login1.Password
pName = ""
Dim strConn As String
strConn = WebConfigurationManager.ConnectionStrings("ConnectionASPX").ConnectionString

Dim Conn As New SqlConnection(strConn)
Conn.Open()


Dim sqlUserName As String
sqlUserName = "SELECT UserName,Password FROM UserName "
sqlUserName &= " WHERE (UserName = @UserName"
sqlUserName &= " AND Password = @Password)"

Dim com As New SqlCommand(sqlUserName, Conn)
com.Parameters.AddWithValue("@UserName", username)
com.Parameters.AddWithValue("@Password", pwd)


Dim CurrentName As String
CurrentName = CStr(com.ExecuteScalar)

If CurrentName <> "" Then
Session("UserAuthentication") = username

Response.Redirect("how-to-StartPage.aspx")
Else
Session("UserAuthentication") = ""
End If

End Sub
End Class

ref from this link: http://www.aspxcode.net/free-asp-net-login-source-code.aspx?Topics=How%20to%20Login%20With%20SQL%20Server%20Database

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

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

Posted by: Poster on: 2/4/2010 [Member] Starter

Up
0
Down
Look at this article

http://www.dotnetfunda.com/articles/article114.aspx

http://www.dotnetfunda.com/articles/article141.aspx

This will give you some clue.

Thanks

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

Posted by: Bubbly on: 2/4/2010 [Member] Bronze

Up
0
Down
Hello,

You can directly use in-built login control for this.

++
Thanks & Regards,
Deepika

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

Posted by: Neeks on: 2/4/2010 [Member] Bronze

Up
0
Down
Hey, don't forget to close connection object after executing the operation.

try

{
if(conn.State != ConnectionState.Closed)
conn.Close();
conn.Open()

}
catch(Exception ex)
{

}
finally
{
conn.Close()
}


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

Login to post response