User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,520 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,816 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1371 | Replies: 9
Reply
Join Date: Sep 2007
Posts: 69
Reputation: geetajlo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
geetajlo geetajlo is offline Offline
Junior Poster in Training

Sign up form

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

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

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
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Solution Re: Sign up form

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

Re: Sign up form

  #4  
Oct 8th, 2007
But How Sandeep
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

  #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  
Join Date: Oct 2007
Posts: 9
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

  #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

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If Page.IsValid Then
            If DBFunction(txtUserName.Text.Trim(), txtPassword.Text.Trim()) Then
                Session("UserName") = txtUserName.Text
                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, False)
            Else

                lblMessage.Text = "Invalid Login!"
                lblMessage.ForeColor = Drawing.Color.Red

            End If

        End If
    End Sub


'Add thi function to connect to database.

  Function DBConnection(ByVal strUserName As String, ByVal strPassword As String) As Boolean
        Dim MyCmd As New SqlCommand("sp_ValidateUser", objConnection)
        MyCmd.CommandType = CommandType.StoredProcedure
        Dim objParam1, objParam2 As SqlParameter
        Dim objReturnParam As SqlParameter
        objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar)
        objParam2 = MyCmd.Parameters.Add("@Password", SqlDbType.VarChar)
        objReturnParam = MyCmd.Parameters.Add("@Num_of_User", SqlDbType.Int)
        objParam1.Direction = ParameterDirection.Input
        objParam2.Direction = ParameterDirection.Input
        objReturnParam.Direction = ParameterDirection.ReturnValue
        objParam1.Value = txtUserName.Text
        objParam2.Value = txtPassword.Text
        Try
            If objConnection.State = ConnectionState.Closed Then
                objConnection.Open()
                MyCmd.ExecuteNonQuery()
            End If
            If objReturnParam.Value < 1 Then
                lblMessage.Text = "Invalid Login!"
                lblMessage.ForeColor = Drawing.Color.Red
            Else
                Return True
            End If
            objConnection.Close()
        Catch ex As Exception
            lblMessage2.Text = "Error Connecting to Database!" & ex.Message
            lblMessage2.ForeColor = Drawing.Color.Red
        End Try

    End Function




Add Stored Procedure  in you database QUERY ANALYZER:


CREATE  PROCEDURE sp_ValidateUser          	(
         		@UserName VARCHAR(50) = NULL,
         		@Password VARCHAR(50) = NULL,
         		@Num_of_User INT = 0
         	)
         AS
         	SET @Num_of_User = (SELECT COUNT(*) AS Num_of_User
         	FROM Members
         	WHERE UserName = @UserName AND Password = @Password)
         RETURN  @Num_of_User
         

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

Re: Sign up form

  #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
 
label1.text="Hi " & Session[UserName] & "!"

Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

  #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  
Join Date: Oct 2007
Posts: 9
Reputation: sandeep.thakur1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sandeep.thakur1's Avatar
sandeep.thakur1 sandeep.thakur1 is offline Offline
Newbie Poster

Re: Sign up form

  #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  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Sign up form

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC