密码正确时密码错误(ASP.NET VB Web表单)

时间:2019-05-13 14:07:58

标签: asp.net vb.net tsql

我正在使用ASP.NET和不带Razor的Visual Basic和T-SQL为网站构建登录页面。尝试使用现有帐户登录时,即使密码正确,我也会收到错误的密码消息。

我曾尝试就此问题对Stack Overflow和Code Project进行一些研究,但大多数人都使用ASP.NET Razor,这不是我正在使用的。

Imports System.Data.SqlClient
Partial Class Login
    Inherits System.Web.UI.Page
    Public Sub Submit(e As Object, sender As EventArgs) Handles submitButton.Click
        Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("RegistrationConnectionString").ConnectionString)
        conn.Open()
        Dim checkuser As String = "SELECT count(*) FROM [Table] WHERE Username='" + user.Text + "'"
        Dim com As SqlCommand = New SqlCommand(checkuser, conn)
        Dim temp As Integer = Convert.ToInt32(com.ExecuteScalar())
        conn.Close()
        If temp = 1 Then
            conn.Open()
            Dim checkpasswordquery As String = "SELECT password FROM [Table] WHERE Username='" + user.Text + "'"
            Dim passComm As SqlCommand = New SqlCommand(checkpasswordquery, conn)
            Dim password As String = passComm.ExecuteScalar().ToString()
            MsgBox(password) //I have this here to test if my password matches (and my password does match)
            If password = pass.Text Then
                MsgBox("Login successful!")
            Else
                MsgBox("Incorrect password. If you would like to reset your password, please email info@maddenu.com")
            End If
        Else
            MsgBox("Incorrect username")
        End If

    End Sub
End Class

我希望收到一个消息框,告诉我登录成功,但是我收到一个消息框,告诉我密码不正确,如果需要重设密码,应该给info@maddenu.com发送电子邮件。

0 个答案:

没有答案