Sign up form
Hi can anyone help me tin asp.net. i want to make a sign up form with linking without returning back. if login successfully then go on welcome page otherwise login fails. just help me plzzz.
geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
Would you like to use Microsoft Membership or have your own custom login? For a custom login, look at below. This sub relies on two textboxes and a submit button. The text boxes are the username and password. This is with an Odbc Database connection. If you use a MySQL connection, change the lines below (which I gave to you).
Sub btnLogin_Click(S As Object, E As EventArgs)
Dim conLogin As OdbcConnection
Dim cmdSelectLoginfo As OdbcCommand
Dim dtrReaderLogin As OdbcDataReader
Dim conStringLogin As String
Dim SQLString As String
Dim strUAID As String
conStringLogin = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString")
conLogin = New OdbcConnection( conStringLogin )
SQLString = "SELECT UserID FROM Users WHERE UserName=? AND UserPassword=?"
'MySQL: SQLString = "SELECT UserID FROM Users WHERE UserName=@userName AND UserPassword=@userPass"
cmdSelectLoginfo = New OdbcCommand( SQLString, conLogin )
cmdSelectLoginfo.Parameters.Add("?userName", (txtUsername.Text.Trim()).ToString())
'MySQL: cmdSelectLoginfo.Parameters.Add("@userName",(txtUsername.Text.Trim()).ToString())
cmdSelectLoginfo.Parameters.Add("?userPass", (txtPassword.Text.Trim()).ToString())
'MySQL: cmdSelectLoginfo.Parameters.Add("@userPass",(txtUsername.Text.Trim()).ToString())
conLogin.Open()
dtrReaderLogin = cmdSelectLoginfo.ExecuteReader()
if dtrReaderLogin.hasrows then
dtrReaderLogin.Close()
strUAID = cmdSelectLoginfo.ExecuteScalar()
Session("UAID") = strUAID
conLogin.Close()
Session("Login") = "Logged"
Response.Redirect ("/loggedin.aspx")
else
Session("Login") = "Failed"
Session("UAID") = ""
conLogin.Close()
dtrReaderLogin.Close()
Response.Redirect ("/loggedin.aspx?log=fail")
'or have this post back and enable a label field with lblname.Visible = true and lblname.Text = "login failed try again."
end if
End Sub
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
geetajlo
Junior Poster in Training
72 posts since Sep 2007
Reputation Points: 8
Solved Threads: 0
I do it this way for myself as it one, looks cleaner, and two, is easier for me to debug.
The way he is talking about is that you can set almost all your values while at Dim, like below:
Dim conLogin As New OdbcConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"))
this specific string reduces the code above by 4 lines, but people just have their own ways of doing it as it suits them better.
You can also elminite the parameters added by just including them directly into the SQL query like:
Dim cmdSelectLoginfo As New OdbcCommand( "SELECT UserID FROM Users WHERE UserName=" & ((txtUsername.Text.Trim()).ToString()) & " AND UserPassword=" & ((txtPassword.Text.Trim()).ToString()), conLogin )
this line reduces code by 5 lines. Use what is best for you for debugging. After making sure it works the way you desire, worry about using less code as it saves bandwidth and load time (but nothing you will most likely have to worry about as it is minimal unless you are dealing with capacities of millions of unique visitors each month.)
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Doing it this way you also need to set authentication in your web.config. So if you come up with errors, check there first.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
SheSaidImaPregy is right !
I forgot to add connection string,that you have to define in your web.config
or do like this in your page
Partial Class Login
Inherits System.Web.UI.Page
Dim objConnection As New SqlConnection("Data Source=SANDEEPTHAKUR\SANDY;database=Northwind;Integrated Security=SSPI") Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Yeah, but if you use this connection more than once (which I am sure of it), then define it in your web.config.
enjoy! :)
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68