Click to See Complete Forum and Search --> : Use NT Security to authenticate VB Application
rthfam
August 30th, 2001, 09:16 AM
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.
berta
August 30th, 2001, 09:24 AM
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/images/bertaplanet.gif'>
</center>
rthfam
August 30th, 2001, 10:20 AM
Thank you, but I cannot get this to work on a client. Window NT 4.0 workstation client.
berta
August 30th, 2001, 10:24 AM
what's the problem U have with this?
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>
rthfam
August 30th, 2001, 10:31 AM
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.
berta
August 30th, 2001, 10:44 AM
yes... I see the problem..
I found this code on www.vb2themax.com... 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/images/bertaplanet.gif'>
</center>
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.