Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB7
Expertise: Intermediate
May 5, 2003



Application Security Testing: An Integral Part of DevOps

CheckWindowsUser - Check whether a username/password pair is correct

<System.Runtime.InteropServices.DllImport("advapi32")> Shared Function _
    LogonUser(ByVal userName As String, ByVal domain As String, _
    ByVal password As String, ByVal dwLogonType As Integer, _
    ByVal dwLogonProvider As Integer, ByRef phToken As Integer) As Integer
End Function

<System.Runtime.InteropServices.DllImport("kernel32")> Shared Function _
    CloseHandle(ByVal hObject As Integer) As Integer
End Function

' 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

Function CheckWindowsUser(ByVal userName As String, ByVal password As String, _
    Optional ByVal domain As String = "") As Boolean
    Const LOGON32_LOGON_NETWORK = 3&

    Dim hToken, ret As Integer

    ' provide a default for the Domain name
    'If domain.Length = 0 Then domain = Nothing
    ' 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
    End If
End Function
Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date