View Single Post
  #13 (permalink)  
Old May 4th, 2005, 05:10 AM
sujithvmenon sujithvmenon is offline
Registered User
Join Date: May 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

quote:Originally posted by pgtips
 Doug, I don't know if you're still interested in this but, for the sake of the archive, I stumbled across this interesting piece of code which uses the LogonUser WinAPI function to validate a given user name and password (note, though, that it does not get the current password of the user)
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 _

' 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, _

    ' a non-zero value means success
    If ret Then
        CheckWindowsUser = True
        CloseHandle hToken
    End If

End Function
BTW I found it on

Hi Phil,
I tried the same code in my VB 6.0 std exe application to validate login agnst domain users.But unfortunately, "LogonUser" returns 0 (zero) even after providing correct username,password & domain name.Mine is a Win2000 domain server in the same n/w and my Vb appln will be installed in Win98/2000 Prof/XP.
Is there any way i can get the sample, working code for user validation be using
Plz give me a suggestion..
rgds & thanx in advance,

Reply With Quote