Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AD Authentication?
Message
 
 
To
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:
01686298
Views:
59
>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
John,

Thank you very much for the reply and the code.

Do average users know their network credentials (username and password)? And do you know of a way to test the above code without having an AD. Or, do you know if a "sample/test" AD is available for a download?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform