by Kamlesh Santani (5 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 17th September 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
You can write this code in the class module (ActiveX dll). If your application maintains users and works only when the user logs in, then this
API Declarations
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
' following parameters have to be passed
' user = username of the sql server
' pwd = password of the sql server
' database = name of the database you are connecting to
' server=name of the server where the database is located (ip address of the server is preferrable rather than the name of the server)
Public Function OpenConnection(ByVal user As String, ByVal pwd As String, ByVal database As String, ByVal server As String)
If cn.State = adStateOpen Then cn.Close
cn.Open "Provider=SQLOLEDB.1;Password= '" & pwd & "'" & ";Persist Security Info=True;User ID= '" & user & "'" & ";Initial Catalog= '" & database & "'" & ";Data Source= '" & server & "'" & ";Connect Timeout=0"
End Function
' validating user
' here you have to pass three parameters
' username,password, and name of the table
' make sure you write the field names of your table while validating the entered values with your field values
Public Function ValidateUser(ByVal username As String, ByVal password As String, ByVal table As String)
If username = "" Then
MsgBox "Please enter Username", vbCritical
Exit Function
ElseIf password = "" Then
MsgBox "Please enter password", vbCritical
Exit Function
End If
If rs.State = adStateOpen Then rs.Close
Dim sql
sql = "select * from " & table & " where username ='" & username & "'" & " and password ='" & password & "'"
rs.Open sql, cn, adOpenKeyset
If rs.RecordCount = 0 Then
MsgBox "You do are not authorised to view this site/software", vbCritical
Exit Function
Else
MsgBox "Login Succeeded",vbinformation
' redirect to another page/show the opening menu for logged users
Exit Function
End If
End Function
No comments have been posted about You can write this code in the class module (ActiveX dll). If your application maintains users and . Why not be the first to post a comment about You can write this code in the class module (ActiveX dll). If your application maintains users and .