Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Verify an AD user and password via VFP6
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows 2000
Network:
Windows 2000 Server
Divers
Thread ID:
01095121
Message ID:
01095246
Vues:
16
>I am using VFP6 SP5 and have an app that accepts a user name and password and verifies it against a VFP table of users.
>
>We now want to verify against the AD user name and password. Is there a way to verify that what is entered is a valid AD user and password combination?

You might try this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/authentication.asp

I once created some test code, but was never able to verify if it worked-- because I don't have a proper server to test.

Let me know if it worked for you or not.

Thanks!

--Paul
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform