Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 4th, 2005, 05:37 AM
Registered User
 
Join Date: May 2005
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old February 20th, 2008, 02:49 AM
Registered User
 
Join Date: Feb 2008
Location: Chennai, TN, India.
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
Reply With Quote
  #3 (permalink)  
Old April 29th, 2008, 08:03 AM
Friend of Wrox
Points: 687, Level: 9
Points: 687, Level: 9 Points: 687, Level: 9 Points: 687, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamilnadu, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.