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>



Reply With Quote
Bookmarks