[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

Verify Active Directory username/password

Is there a function built into VB or ADSI that can verify a Active Directory username and password? We have a database system that we want to add a level of security to. I want the user to type in their window username and password into two text boxes. Then I want VB to check those credentials against Active Directory and grant access to the next form if username and password are correct, and display an error message and deny access if not.

I have come accross a few documents in the internet that refrerce using the LogonUser() function in advapi32.dll to accoplish this. I tried to reference dll in my VB6 code, but I recieved the following error: "Can't add reference to the specified file." What am I doing wrong, or is there a better way to accomplish this?

Thanks in advanced!
1 Solution
The ADVAPI32.DLL is NOT a so-called ActiveX DLL, so you cannot add it as a reference from the Project->References menu in VB.
It is a DLL that contains/exposes API to be called by other programs.

By the way the LogonUser API function is in the Kerner32.dll.  To use it try this:

Public Declare Function LogonUser Lib "kernel32" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long

Private Sub Command1_Click()

  If LogonUser("JohnDoe", "myDomain", "myPassword", 0&, 0&)
     MsgBox "Logon successful"
  End If

End Sub

Put the LogonUser declaration at the in the Declaration section of the form, or put it in a standard module.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now