SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Login form help

  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Login form help

    Hi Folks,

    Can someone please help me with the code below

    I keep getting invalid crendials, even though I enter the right username and password, can anyone please help me fault find the problem?

    Thanks


    Code:
    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    
    <script runat="server">
        Protected Sub Button1_Click(ByVal sender As Object, _
          ByVal e As System.EventArgs)
    
          
               ' Define database connection
    	Dim connStr As String = ConfigurationManager.ConnectionStrings("SqlDataSource1").ConnectionString
        Dim conn As New SqlConnection(connStr)
        
        
           Dim cmd As SqlCommand
           Dim cmdString As String = "SELECT Username, Password FROM LU.users WHERE" & _
              " ((Username = @Username) AND (Password = @Password))"
            
            
       
    	
         
           cmd = New SqlCommand(cmdString, conn)
            
           cmd.Parameters.Add("@Username", SqlDbType.VarChar, 50)
           cmd.Parameters("@Username").Value = TextBox1.Text
           cmd.Parameters.Add("@Password", SqlDbType.VarChar, 50)
           cmd.Parameters("@Password").Value = TextBox1.Text
            
           conn.Open()
            
           Dim myReader As SqlDataReader
            
           myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            
           If myReader.Read() Then
                   Response.Redirect("")
           Else
              Response.Write("Invalid credentials")
           End If
            
           myReader.Close()    
       End Sub
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Login Page</title>
    </head>
    <body> <form id="form1" runat="server">
        <div>
            Username<br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
            <br />
            Password<br />
            <asp:TextBox ID="TextBox2" runat="server" 
             TextMode="Password"></asp:TextBox><br />
            <br />
            <asp:Button ID="Button1" OnClick="Button1_Click" runat="server" 
             Text="Submit" />
        </div></form>
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cmd.Parameters("@Password").Value = TextBox1.Text

    should be

    cmd.Parameters("@Password").Value = TextBox2.Text


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •