VB.NET, SQL Server  •  Retrieve Credential Information

Listing 3. This code contains the SecurityUser object's Validate method. This version of Validate uses a SQL Server database to retrieve user credential information.

Public Function Validate() As Boolean
   Dim strSQL As String
   Dim objConnection As New SqlConnection _
      ("SQL Connection String")
   Dim objCommand As New SqlCommand()
   Dim intRowCount As Integer

   ' This assumes that there a SECURITY table in 
   ' our DB
   strSQL = "SELECT count(*) as 'RowCount' " & _
      "FROM SECURITY WHERE" & " NAME = '" & _
      Me.Name & "' AND PASSWORD = '" & _
      Me.Password & "'"
   objConnection.Open()
   objCommand = New SqlCommand(strSQL, _
      objConnection)
   intRowCount = objCommand.ExecuteScalar()
   objConnection.Close()
   If intRowCount = 0 Then
      Return False
   Else
      Return True
   End If
End Function