"Dooza" <st*****@SPAM.dooza.tvwrote in message
news:ef**************@TK2MSFTNGP06.phx.gbl...
Hi there,
Using classic ASP I want to check if a username and password are correct
before passing the details on to an object (stocktake module) that uses
them to authenticate the object. The object defaults to a preset user if
the authentication fails and doesn't warn the user, so I wanted to do the
check manually before passing it to the object.
Does anyone have any resources?
You will need to create a COM object to do this, it can't be done in script.
On the bright side, the code to accomplish this is fairly trivial, all you
need to do is call the LogonUser API. (Note that if it succeeds you should
close the token handle it returns.)
If you wanted to do it in VB6, it would look something like this:
Public Declare Function LogonUser Lib "kernel32" 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
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle"
(ByVal hObject As Long) As Long
Public Const LOGON32_LOGON_NETWORK = 3
Public Const LOGON32_PROVIDER_DEFAULT = 0
Function ValidateCredentials( _
UserName As String, _
Password As String, _
Domain As String _
) As Boolean
Dim hToken As Long
If (LogonUser(UserName, Domain, Password, n, n, hToken) <0) Then
CloseHandle hToken
ValidateCredentials = True
End If
End Function
-Mark
Cheers,
Steve