Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2005, 05:37 AM
Registered User
 
Join Date: May 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB - Active Directory Validation

I have a VB application that validates users from a database table at present.Now I want it to validate against the domain users, instead of the existing setup.I will be specifying the domain name, the user will be asked to enter his/her windows domain user name & password in the login form. I ve tried applying various codes to meet my requirement & unfortunately, I m yet to get a true solution.
Domain server is Win 2000 & the VB appln will be running on Win 98/NT/2000/XP systems.
I m pasting below the code that i ve tried...

Private 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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
    Long
Const LOGON32_PROVIDER_DEFAULT = 0&
Const LOGON32_LOGON_NETWORK = 3&
Const LOGON32_LOGON_INTERACTIVE = 2&
Const LOGON32_PROVIDER_WINNT50 = 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

Private 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
    End If

End Function

"LogonUser" returns 0 (zero) even if i provide the correct inputs.

Rgds,
SVM



 
Old February 20th, 2008, 02:49 AM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I am also facing the same problem in my vb6.0 application. But the difference is we are using Window 2003 server Active directory service. Please let me know if you have the exact code to validate the user and password from Active directory service...

S.Sakthivel
 
Old April 29th, 2008, 08:03 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

I have checked with above code in our network and it, and its working PROPERLY with proper inputs and shows false when inputs do not match.

Private Sub Form_Load()
MsgBox CheckWindowsUser("guest", "guest"): Rem just an example, change it to proper username of your local PC/AD user
End Sub

copy and paste the code and try calling like this...

If not working then, it's due to improper AD setup or something else....

Hope this helps.

With Regards,
Raghavendra Mudugal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Active Directory TCSE305 Windows Server 1 November 22nd, 2006 01:26 AM
Connecting to Active Directory database via VB.NET djoherl Pro VB Databases 1 May 20th, 2005 05:23 PM
About Active Directory apalmero VS.NET 2002/2003 1 November 9th, 2003 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.