CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2001
    Posts
    3

    Use NT Security to authenticate VB Application

    Hi,

    I am able to authenticate a user in an ASP page using NT security, but would like to do the same in another project using just a Visual Basic application on the client not using a web browser, ASP or IIS. Is this possible?

    Thank you.


  2. #2

    Re: Use NT Security to authenticate VB Application


    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&

    ' 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

    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





    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  3. #3
    Join Date
    Aug 2001
    Posts
    3

    Re: Use NT Security to authenticate VB Application

    Thank you, but I cannot get this to work on a client. Window NT 4.0 workstation client.


  4. #4

    Re: Use NT Security to authenticate VB Application

    what's the problem U have with this?

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  5. #5
    Join Date
    Aug 2001
    Posts
    3

    Re: Use NT Security to authenticate VB Application

    If I pass the same username and password and no domain, a valid domain or "." for domain to CheckWindowsUser, the function LogonUser always returns zero. I am hardcoding the strings I am passing to the CheckWindowsUser function. [Example: CheckWindowsUser("validusername", "validpassword", "DOMAINNAME") ]

    Thanks.


  6. #6

    Re: Use NT Security to authenticate VB Application

    yes... I see the problem..
    I found this code on www.**************... but I never use it... I study for the problem... then I say U...

    hi,brt

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured