ARTICLE

User Authentication(Class/Ado.NET Demo)

Posted by Arun Nair Articles | Visual Basic 2010 June 26, 2003
Here, you'll learn the use of a VB.NET class library project through this User Authentication example. Instead of the conventional ADO recordset, I've used the new Dataset(check out my previous article for more information on Datasets) to traverse.
Download Files:
 
Reader Level:

Introduction.

Here, you'll learn the use of a VB.NET class library project through this User Authentication example. Instead of the conventional ADO recordset, I've used the new Dataset(check out my previous article for more information on Datasets) to traverse. Once the class is ready and compiled, you can reference this class in any VB.NET project by selecting the Project -> Add Reference menu option.

But first, you need to create a database with a table called REGUSERS and the field's username and password. After the database creation, map it to a DSN called authtest.

Hope you find this code helpful enough in your .NET endeavor. Long then.

Source Code

Imports System.ComponentModel
Imports System.Data
Imports System.Data
Imports System.Data.SQL
Imports System.Data.ADO
Imports Microsoft.VisualBasic.Compatibility
Public Class CWS
Inherits System.ComponentModel.Component
Const cnStr As String = "DSN=authTest"
Public Function authenticate(ByVal username As String, ByVal password As String) As Boolean
'Create an ADOConnection instance
Dim objConn As ADOConnection
objconn =
New ADOConnection()
'Set the ADOCOnnection object's connection string property
objconn.ConnectionString = cnStr
objconn.Open()
'Create a SQL string
Dim strSQL As String = "select username from regusers " & _
"where username='" & userName & "' " & _"and password='" & passWord & "'"
'Create an instance of the ADODatasetcommand and Dataset objects
Dim objDSCommand As ADODataSetCommand
Dim objDataset As DataSet
objdataset =
New DataSet()
objdscommand =
New ADODataSetCommand(strsql, objconn)
objdscommand.FillDataSet(objdataset, "auth")
Try
If
objDataset.Tables(0).Rows(0).Item(0).ToString <> "" Then
Return
True
End
If
Catch
Return
False
End
Try
objconn.Close()
objconn =
Nothing
End
Function
Public
Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
' TODO: Add any initialization after the InitializeComponent() call
End Sub
#Region " Component Designer generated code "
'Required by the Component Designer
Private components As Container
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
components =
New System.ComponentModel.Container()
End Sub
#End Region
End
Class

share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor