LOCAL cServerTest,cUserTest,cPwdTest,lValidUser,oAuthADSI ************************************************************************ * DEFINITION: * LDAP, Lightweight Directory Access Protocol, is an Internet protocol that * email and other programs use to look up information from a server. ************************************************************************ ************************************************************************ * DEFINITION * Active Directory Service Interfaces (ADSI) enable systems administrators * and developers of applications to easily query for and manipulate directory * service objects. ************************************************************************ ************************************************************************ * * You won't be able to use the LDAP provider to access Active Directory * unless you have a domain controller running Windows 2000/2003 and you * have installed ADSI (Active Directory Service Interfaces). * ************************************************************************ * * Test variables * m.cServerTest = "//192.168.2.100" m.cUserTest = "someuser" m.cPwdTest = "qazwsx" * * Create the object to authenticate active directory user * oADSI = CREATEOBJECT("bizActiveDirectoryAuthenticate") * * Authenticate here. * m.lValidUser = oADSI.Authenticate(m.cServerTest,m.cUserTest,m.cPwdTest) * * Did we get authentication? * IF m.lValidUser * * Active directory user is valid * = MESSAGEBOX("User is valid.") ELSE * * Create error message here * = MESSAGEBOX(STR(oADSI.ErrID) + " " + oADSI.ErrMsg) ENDIF RETURN DEFINE CLASS bizActiveDirectoryAuthenticate AS Custom OKUser = .t. ErrMsg = "" ErrID = 0 PROCEDURE Error LPARAMETERS nError,cMethod,nLine * * Get last error message * = AERROR(aErrorArray) * * Set properties that fail user authentication * This.OKUser = .f. This.ErrMsg = aErrorArray[2] This.ErrID = m.nError ENDPROC FUNCTION Authenticate LPARAMETERS cHostName,cUser,cPassWord LOCAL ADS_SECURE_AUTHENTICATION LOCAL oADSI,oADSI2,cADsPath,cProvider ADS_SECURE_AUTHENTICATION = 1 * * Clear properties * This.OKUser = .t. This.ErrMsg = "" This.ErrID = 0 m.cProvider = "LDAP:" && Another possibility is try using "WinNT:" * * LDAP://HostName[:PortNumber][/DistinguishedName] * m.cADsPath = m.cProvider + m.cHostName * * The following code shows how to use the OpenDSObject method to authenticate a user. * If the userid and/or password fail then the "Error" method is called. * * OpenDSObject is an ADSI method. * oADSI = GETOBJECT(m.cProvider) oADSI2 = oADSI.OpenDSObject(m.cADsPath,m.cUser,m.cPassword,ADS_SECURE_AUTHENTICATION) RETURN This.OKUser ENDFUNC ENDDEFINE