Public Partial Class Webforms_Login
    Inherits System.Web.UI.Page

    Private WithEvents aUser As User


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.Name <> "" Then
            lbSignOut.Visible = True
        End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        lblError.text = ""
        Dim strUsername, strPassword As String
        strUsername = tbUsername.Text
        strPassword = tbPassword.Text
        aUser = New User
        aUser.Username = strUsername
        aUser.Password = strPassword

        If aUser.Exists(strUsername) Then
            If aUser.CheckLogin(strUsername, strPassword) Then
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(strUsername, False)
            Else
                'Password incorrect
                lblError.Text = "Password incorrect!"
            End If
        Else
            'User not registered
            lblError.Text = "Username incorrect!"
        End If
    End Sub

    Protected Sub lbSignOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbSignOut.Click
        System.Web.Security.FormsAuthentication.SignOut()
        lbSignOut.Visible = False
    End Sub
End Class