Validate username and password from AD


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Validate username and password from AD

  1. #1
    Join Date
    Jul 2004
    Location
    U.K
    Posts
    14

    Validate username and password from AD

    Hi I am trying to validate a username and password against Active directory. Does any one have some sample code or point me in the right direction. It would need to work on both Winxp and 2000.

    The code below works fine on Winxp but not on Win2000 ??????

    I did get this code from an other site but can't get it to work on 2000

    Code:
    Public Declare Function LogonUser Lib "Advapi32" 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 
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _ 
        Long 
    Const LOGON32_PROVIDER_DEFAULT = 0& 
    Const LOGON32_LOGON_NETWORK = 3& 
    
    ' Check whether a username/password pair is correct 
    ' 
    ' if DOMAIN is omitted, it uses the local account database 
    ' and then asks trusted domains to search their account databases 
    ' until it finds the account or the search is exhausted 
    ' use DOMAIN="." to search only the local account database 
    ' 
    '  IMPORTANT: works only under Windows NT and 2000 
    
    Public Function CheckWindowsUser(ByVal UserName As String, _ 
        ByVal Password As String, Optional ByVal Domain As String) As Boolean 
        Dim hToken As Long, ret As Long 
    
        ' provide a default for the Domain name 
        If Len(Domain) = 0 Then Domain = vbNullString 
        ' check the username/password pair 
        ' using LOGON32_LOGON_NETWORK delivers the best performance 
        ret = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, _ 
            LOGON32_PROVIDER_DEFAULT, hToken) 
        
        ' a non-zero value means success 
        If ret Then 
            CheckWindowsUser = True 
            CloseHandle hToken 
            Else 
            do something
        End If 
    
    End Function

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

Similar Threads

  1. Login (Java Servlet/Database)
    By cappo in forum Java
    Replies: 1
    Last Post: 04-26-2005, 07:16 PM
  2. Authenticating Username & Password
    By Johan in forum VB Classic
    Replies: 4
    Last Post: 05-04-2001, 09:23 PM
  3. Authenticating Username & Password
    By Johan in forum VB Classic
    Replies: 0
    Last Post: 05-04-2001, 06:49 AM
  4. Administrator username and password
    By Alex Ruiz in forum VB Classic
    Replies: 0
    Last Post: 02-14-2001, 05:44 PM
  5. Verify a NT4 username and password
    By Peter Thompson in forum VB Classic
    Replies: 0
    Last Post: 11-14-2000, 12:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center