Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AD Authentication?
Message
From
28/02/2023 13:50:39
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01686248
Message ID:
01686296
Views:
136
Likes (1)
Hi Dmitry,

>> Your post and your program is VFP, right?
>>Also, if the above assumption is correct, what are you trying to achieve? In simple terms?

User logs into my app using their network credentials, which might not be the same as user logged into machine. These are validated against Active Directory/LDAP.

The following code works against both Microsoft Active Directory and Linux variants of LDAP, e.g. OpenLDAP.
function LDAP_Authenticate(lcDN,lcpassword,lcServer,liPort)

Declare long ldap_init In Wldap32 String Hostname,long portnumber
Declare long ldap_bind_s In wldap32 Long iHandle,String cDN,string cCredential, long iMethod
DECLARE ldap_set_option IN wldap32 long iHandle,integer option,integer ivalue
Declare ldap_unbind In wldap32 Long iHandle

#Define LDAP_PORT               389
#Define LDAP_SSL_PORT           636
#Define LDAP_AUTH_SIMPLE        0x80
#DEFINE LDAP_OPT_VERSION        0x11

#Define LDAP_SUCCESS    	0x00

local liSessionHandle,liTemp,liAuth

*--- sample credentials for free online LDAP
lcDN="uid=einstein,dc=example,dc=com"
lcPassword="password"
lcServer="ldap.forumsys.com"
liPort=389

liSessionHandle=LDAP_INIT(m.lcServer,m.liPort)  &&LDAP session handle

If m.liSessionHandle=0
	Error "Unable to connect to "+m.lcServer+": "+getwindowserror() &&getwindowserror function pulls latest Windows error
ELSE
	ldap_set_option(m.lisessionHandle,LDAP_OPT_VERSION,3)	&&version 3; optional
	liAuth=-1
	liAuth=LDAP_BIND_S(m.liSessionHandle,lcDN,lcPassword,LDAP_AUTH_SIMPLE )
	ldap_unbind(m.liSessionHandle)

	If m.liAuth=LDAP_SUCCESS   &&user is authenticated
	Else
		Error "Server returned Error Code "+Transform(m.liAuth)
	Endif
Endif
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform