views:

56

answers:

1

I need to test a username and password pair against a given domain in a VBScript. The script will know the username, password, and domain against which it needs to check for access, and all I need returned is a true or false as to whether the account is valid.

Can anyone suggest a good way to accomplish this? Thanks!

A: 

The following function will test a username/password against the given domain:

function fnCheckAccess(strDomain, strUserID, strUserPWD)

const ADS_SECURE_AUTHENTICATION = &h0001
const ADS_CHASE_REFERRALS_ALWAYS = &H60

dim objDSO
dim objUser
dim strPath

strPath = "LDAP://" & strDomain & "/OU=Users,DC=" & strDomain

On Error Resume Next
set objDSO = GetObject("LDAP:")
set objUser = objDSO.OpenDSObject (strPath, strUserID, strUserPWD, ADS_SECURE_AUTHENTICATION OR ADS_CHASE_REFERRALS_ALWAYS)
if Err.Number <> 0 then
    MsgBox "Incorrect Password for " & g_strDomain & "\" & g_strUserID & "." & vbCRLF & vbCRLF & "Error " & Err.Number & ": " & Err.Description, 16, "Access Denied"
    fnCheckAccess = False
else
    fnCheckAccess = True
end if
Err.Clear
On Error Goto 0

set objDSO = Nothing
set objUser = Nothing

end function
c0nsumer