首页 > 解决方案 > 如果登录详细信息错误,向用户显示消息?

问题描述

如果用户输入错误的登录详细信息,我该如何做到这一点,他们会收到错误消息?我试过的东西不起作用,当我按下按钮时没有任何反应

Private Sub Loginbtn_Click(sender As Object, e As EventArgs) Handles Loginbtn.Click
    'Allows user into app with specifc username & password (Login ID 1)
    If Usernamebtn.Text = "Business1" And Passwordbtn.Text = "qwerty1" Then
        MsgBox("You are Logged In!", MessageBoxIcon.Information, "Login")
        AppMenu.Show()
        Me.Hide()


    Else

        'If no username or password field empty
        If Usernamebtn.Text = "" Or Passwordbtn.Text = "" Then
            MsgBox("Please Fill in the Username and Password!", MsgBoxStyle.Critical, "Error")

            'If no username or password dosent match Login ID 
            If Usernamebtn.Text <> "Business1" AndAlso Passwordbtn.Text = "qwerty1" Then
                MsgBox("Dosen't Exist, Please try again.", MsgBoxStyle.Critical, "Error")
            Else
            End If
        End If
    End If
End Sub

标签: vb.netvisual-studioauthentication

解决方案


试试这个方法

Private Sub Loginbtn_Click(sender As Object, e As EventArgs) Handles Loginbtn.Click
    'Allows user into app with specifc username & password (Login ID 1)
    If Usernamebtn.Text = "Business1" AndAlso Passwordbtn.Text = "qwerty1" Then
        MsgBox("You are Logged In!", MessageBoxIcon.Information, "Login")
        AppMenu.Show()
        Me.Hide()
    Else
        'If username or password field empty
        If Usernamebtn.Text = "" OrElse Passwordbtn.Text = "" Then
            MsgBox("Please Fill in the Username and Password!", MsgBoxStyle.Critical, "Error")
        Else
            MsgBox("User dosen't exist OR password incorrect, Please try again.", MsgBoxStyle.Critical, "Error")
        End If
    End If
End Sub

会发生一些事情。


推荐阅读