Sign up form

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 72
Reputation: geetajlo is an unknown quantity at this point 
Solved Threads: 0
geetajlo geetajlo is offline Offline
Junior Poster in Training

Sign up form

 
0
  #1
Oct 2nd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

 
0
  #2
Oct 2nd, 2007
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).

  1. Sub btnLogin_Click(S As Object, E As EventArgs)
  2. Dim conLogin As OdbcConnection
  3. Dim cmdSelectLoginfo As OdbcCommand
  4. Dim dtrReaderLogin As OdbcDataReader
  5. Dim conStringLogin As String
  6. Dim SQLString As String
  7. Dim strUAID As String
  8. conStringLogin = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString")
  9. conLogin = New OdbcConnection( conStringLogin )
  10. SQLString = "SELECT UserID FROM Users WHERE UserName=? AND UserPassword=?"
  11. 'MySQL: SQLString = "SELECT UserID FROM Users WHERE UserName=@userName AND UserPassword=@userPass"
  12. cmdSelectLoginfo = New OdbcCommand( SQLString, conLogin )
  13. cmdSelectLoginfo.Parameters.Add("?userName", (txtUsername.Text.Trim()).ToString())
  14. 'MySQL: cmdSelectLoginfo.Parameters.Add("@userName",(txtUsername.Text.Trim()).ToString())
  15. cmdSelectLoginfo.Parameters.Add("?userPass", (txtPassword.Text.Trim()).ToString())
  16. 'MySQL: cmdSelectLoginfo.Parameters.Add("@userPass",(txtUsername.Text.Trim()).ToString())
  17. conLogin.Open()
  18. dtrReaderLogin = cmdSelectLoginfo.ExecuteReader()
  19. if dtrReaderLogin.hasrows then
  20. dtrReaderLogin.Close()
  21. strUAID = cmdSelectLoginfo.ExecuteScalar()
  22. Session("UAID") = strUAID
  23. conLogin.Close()
  24. Session("Login") = "Logged"
  25. Response.Redirect ("/loggedin.aspx")
  26. else
  27. Session("Login") = "Failed"
  28. Session("UAID") = ""
  29. conLogin.Close()
  30. dtrReaderLogin.Close()
  31. Response.Redirect ("/loggedin.aspx?log=fail")
  32. 'or have this post back and enable a label field with lblname.Visible = true and lblname.Text = "login failed try again."
  33. end if
  34. End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 10
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

 
0
  #3
Oct 8th, 2007
Quite complex one. Can be done in 8 line code.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 72
Reputation: geetajlo is an unknown quantity at this point 
Solved Threads: 0
geetajlo geetajlo is offline Offline
Junior Poster in Training

Re: Sign up form

 
0
  #4
Oct 8th, 2007
But How Sandeep
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

 
0
  #5
Oct 8th, 2007
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.)
Last edited by SheSaidImaPregy; Oct 8th, 2007 at 11:07 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 10
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

 
0
  #6
Oct 8th, 2007
It in VB and give best performance.
In C# i am posting later.
Just add this code. if any query revert.
Sandeep

  1.  
  2. Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  3. If Page.IsValid Then
  4. If DBFunction(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then
  5. Session("UserName") = txtUserName.Text
  6. FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)
  7. Else
  8.  
  9. lblMessage.Text = "Invalid Login!"
  10. lblMessage.ForeColor = Drawing.Color.Red
  11.  
  12. End If
  13.  
  14. End If
  15. End Sub
  16.  
  17.  
  18. 'Add thi function to connect to database.
  19.  
  20. Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
  21. Dim MyCmd As New SqlCommand("sp_ValidateUser", objConnection)
  22. MyCmd.CommandType = CommandType.StoredProcedure
  23. Dim objParam1, objParam2 As SqlParameter
  24. Dim objReturnParam As SqlParameter
  25. objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar)
  26. objParam2 = MyCmd.Parameters.Add("@Password", SqlDbType.VarChar)
  27. objReturnParam = MyCmd.Parameters.Add("@Num_of_User", SqlDbType.Int)
  28. objParam1.Direction = ParameterDirection.Input
  29. objParam2.Direction = ParameterDirection.Input
  30. objReturnParam.Direction = ParameterDirection.ReturnValue
  31. objParam1.Value = txtUserName.Text
  32. objParam2.Value = txtPassword.Text
  33. Try
  34. If objConnection.State = ConnectionState.Closed Then
  35. objConnection.Open()
  36. MyCmd.ExecuteNonQuery()
  37. End If
  38. If objReturnParam.Value < 1 Then
  39. lblMessage.Text = "Invalid Login!"
  40. lblMessage.ForeColor = Drawing.Color.Red
  41. Else
  42. Return True
  43. End If
  44. objConnection.Close()
  45. Catch ex As Exception
  46. lblMessage2.Text = "Error Connecting to Database!" & ex.Message
  47. lblMessage2.ForeColor = Drawing.Color.Red
  48. End Try
  49.  
  50. End Function
  51.  
  52.  
  53.  
  54.  
  55. Add Stored Procedure in you database QUERY ANALYZER:
  56.  
  57.  
  58. CREATE PROCEDURE sp_ValidateUser (
  59. @UserName VARCHAR(50) = NULL,
  60. @Password VARCHAR(50) = NULL,
  61. @Num_of_User INT = 0
  62. )
  63. AS
  64. SET @Num_of_User = (SELECT COUNT(*) AS Num_of_User
  65. FROM Members
  66. WHERE UserName = @UserName AND Password = @Password)
  67. RETURN @Num_of_User
  68.  

you have to name you button btnSubmit
and textboxes
txtUserName
txtPassword
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 10
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

 
0
  #7
Oct 8th, 2007
Thi VB Code wil automatically search for Default.aspx page. If Default.aspx is not in your poject, it will give error.
For session, To display Hi Sandeep ! , like this, u have to take a label on default and set
  1.  
  2. label1.text="Hi " & Session[UserName] & "!"
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

 
0
  #8
Oct 8th, 2007
Doing it this way you also need to set authentication in your web.config. So if you come up with errors, check there first.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 10
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

 
0
  #9
Oct 8th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

 
0
  #10
Oct 8th, 2007
Originally Posted by sandeep.thakur1 View Post
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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC