asp.net problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahsan2011
    New Member
    • Apr 2007
    • 10

    asp.net problem...

    hi...learning asp.net ...
    have a problem...

    created two pages..
    one hs a username and password...
    second page is a redirect from button click in first page...
    need to authenticate the econd page...
    please help with the codes in C#.net..
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    This question is being moved to the .NET forum.

    ADMIN

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by ahsan2011
      hi...learning asp.net ...
      have a problem...

      created two pages..
      one hs a username and password...
      second page is a redirect from button click in first page...
      need to authenticate the econd page...
      please help with the codes in C#.net..

      Hi there Ahsan,

      Have you thought about how you are going to authenticate the user's credentials? (Thought about how to verify the user name and password are valid?)

      The most common way to validate user credentials is:
      In your button click on the first page you take the user name and password provided and check them against the values you have stored in a database.

      Cheers!

      -Frinny

      Comment

      • bhar
        Banned
        New Member
        • Apr 2006
        • 37

        #4
        Hi,

        Benefits of Forms-Based Authentication

        1. Developer can configure Forms-based authentication for various parts of the website differ ently, because the Web.config is a hierarchical XML document.
        2. Administrator and developer can change the authentication scheme quickly and easily in the Web.config file
        3. Administration is centralized because all the authentication entries are in one place - Web.config file.

        Authenticating Users with a Database Table

        To support a custom user registration system, we need to store usernames and passwords in a database table, so that we can make this as a scalable solution.

        Create a table in the FinAccounting Database and named as UserTable. We can create a table using SQL Query Analyzer or Enterprise Manager. The command to do this task is given below.
        [code=sql]
        CREATE TABLE UserTable
        (
        u_id INT NULL IDENTITY,
        u_username VARCHAR(20),
        u_password VARCHAR(20)
        )[/code]

        We need to place the following code in the login.aspx (HTML view window) as shown below.
        [code=vb]
        <hr>
        <asp:HyperLin k ID="lnkRegister " Text="Click here to Register!" Runat="server" />
        of the UserTable database table. We need to write the following code in the login.aspx.

        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

        Dim myconnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim myparameter As SqlParameter
        Dim intResult As Integer

        myconnection = New SqlConnection(“ Data Source=sys1;Int egrated Security=SSPI;I nitial Catalog=FinAcco unting”)
        myconnection.Op en()
        Dim strSQL As String
        strSQL = “SELECT * FROM UserTable WHERE u_username = @Username AND u_password = @Password”

        Dim oCommand As New SqlCommand(strS QL, myconnection)
        ‘ Add the parameters for the query.
        oCommand.Parame ters.Add(“@User name”, txtUsername.Tex t.Trim())
        oCommand.Parame ters.Add(“@Pass word”, txtPassword.Tex t.Trim())
        Dim dr As SqlDataReader
        dr = oCommand.Execut eReader(Command Behavior.CloseC onnection)

        Try
        If dr.Read() Then
        Response.Write( “We’re logged in”)
        FormsAuthentica tion.RedirectFr omLoginPage(txt Username.Text, False)
        Else
        ‘Username and password DO NOT match
        Response.Write( “Login failed”)
        End If
        Catch ex As Exception
        Finally
        dr.Close()
        myconnection.Cl ose()
        myconnection.Di spose()
        oCommand.Dispos e()
        End Try
        End Sub
        [/code]
        [Link Removed]
        Last edited by pbmods; Oct 22 '07, 12:02 PM. Reason: Added CODE tags.

        Comment

        • ahsan2011
          New Member
          • Apr 2007
          • 10

          #5
          thank u..will try...but wanted the code in C#..wil try to convert it..

          Comment

          Working...