This example provides you have an access database with a table named USERS having fields USERID and PASSWORD in it. Also you must have a connection string to your database.

In your main form you will need to call frmLogin:

vb Code:
  1. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal As System.EventArgs) Handles btnLogin.Click
  2.      Dim frm As New frmLogin
  3.      Dim ret As DialogResult = frm.ShowDialog()
  4.      If ret <> Windows.Forms.DialogResult.OK Then
  5.          MsgBox("Login failed", MsgBoxStyle.Exclamation)
  6.      Else
  7.          ' Logged in
  8.      End If
  9. End Sub

Now you should create a frmLogin having txtLogin and txtPassword (textboxes) and btnLogin (a button):

vb Code:
  1. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal As System.EventArgs) Handles btnLogin.Click
  2.         ' Create a connection to your database:
  3.         Dim conn As New OleDbConnection("your connection string goes here")
  4.         ' Create a query string (with parameters):
  5.         Dim sql As String = "SELECT USERID FROM USERS WHERE USERID=@p_userid AND PASSWORD=@p_passw;"
  6.         Dim cmd As New OleDbCommand(sql, conn)
  7.  
  8.         ' Add parameters
  9.         With cmd
  10.             .Parameters.AddWithValue("p_userid", txtLogin.Text)
  11.             .Parameters.AddWithValue("p_passw", txtPassword.Text)
  12.         End With
  13.  
  14.         ' Open your connection and perform the query
  15.         Try
  16.             conn.Open()
  17.             Dim usr As String = cmd.ExecuteScalar.ToString
  18.             If Not (IsDBNull(usr)) AndAlso usr = txtLogin.Text Then
  19.                 Me.DialogResult = Windows.Forms.DialogResult.OK   ' Return OK (user is found password matches)
  20.             Else
  21.                 Me.DialogResult = Windows.Forms.DialogResult.Cancel ' Return Cancel (query returned nothing)
  22.             End If
  23.         Catch ex As Exception
  24.             ' Catch database connection or query errors:
  25.             MsgBox("Could not connect to database or database error." & Environment.NewLine &
  26.                     "Error message:" & ex.Message)
  27.             Me.DialogResult = Windows.Forms.DialogResult.Cancel
  28.         Finally
  29.             ' Close connection
  30.             conn.Close()
  31.             Me.Close()
  32.         End Try

This is a very simple mechanism which provides almost no security at all since usernames and passwords are stored in unencrypted forms and the database itself can be compromised.