Imports System.Data.SqlClient

Public Class frmLogin

    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim strPass As String

        If UsernameTextBox.Text = "" Then UsernameTextBox.Focus() : Exit Sub

        If PasswordTextBox.Text = "" Then PasswordTextBox.Focus() : Exit Sub

        strPass = GetFieldValue("SELECT Username, Password FROM Users WHERE Username='" & UsernameTextBox.Text & "'", "Password")

        If LCase(PasswordTextBox.Text) = LCase(strPass) And strPass <> "Nothing" Then
            Dim f As Form = Application.OpenForms.Item("mdiMain")

            If f Is Nothing Then
                Dim MainForm As New mdiMain

                MainForm.Show()
            Else
                f.BringToFront()
            End If

            Me.Hide()
        Else
            MsgBox("Invalid password.Please try again!", MsgBoxStyle.Exclamation)
            PasswordTextBox.Focus()
        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

End Class
