944,183 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 3743
  • ASP.NET RSS
Oct 2nd, 2007
0

Sign up form

Expand Post »
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.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
geetajlo is offline Offline
72 posts
since Sep 2007
Oct 2nd, 2007
0

Re: Sign up form

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).

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Oct 8th, 2007
0

Re: Sign up form

Quite complex one. Can be done in 8 line code.
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sandeep.thakur1 is offline Offline
10 posts
since Oct 2007
Oct 8th, 2007
0

Re: Sign up form

But How Sandeep
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
geetajlo is offline Offline
72 posts
since Sep 2007
Oct 8th, 2007
0

Re: Sign up form

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.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Oct 8th, 2007
0

Re: Sign up form

It in VB and give best performance.
In C# i am posting later.
Just add this code. if any query revert.
Sandeep

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sandeep.thakur1 is offline Offline
10 posts
since Oct 2007
Oct 8th, 2007
0

Re: Sign up form

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
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. label1.text="Hi " & Session[UserName] & "!"
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sandeep.thakur1 is offline Offline
10 posts
since Oct 2007
Oct 8th, 2007
0

Re: Sign up form

Doing it this way you also need to set authentication in your web.config. So if you come up with errors, check there first.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Oct 8th, 2007
0

Re: Sign up form

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
Reputation Points: 8
Solved Threads: 0
Newbie Poster
sandeep.thakur1 is offline Offline
10 posts
since Oct 2007
Oct 8th, 2007
0

Re: Sign up form

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!
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: UPDATE query problem
Next Thread in ASP.NET Forum Timeline: Crystal Reports for ASP.Net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC