Verify Active Directory username/password

Posted on 2006-06-08
Last Modified: 2012-08-13
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!
Question by:omidboloori
    1 Comment
    LVL 12

    Accepted 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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now