|
From: Kurt B. <ku...@sd...> - 2011-11-09 13:45:46
|
Hi all,
Tony Caduto has provided this example on the Embarcadero winsock NG... It does work!!!
Thanks to Tony and Lucas!
Tony wrote:
I cut this stuff out of a authentication object I created, I don't want to post the whole thing since there is a bunch of other non related stuff in it.
This should get you going, the key is to concatenate the AD username with '@your.ad.domain.name'
After you succesfully bind, you can then do searches against the AD directory by supplying a base DN
and using the search function of the ldapsend unit.
I have found this to be faster than other methods and it's solid. You do need to get the trunk version of
synapse so it works with the later versions of delphi.
{code}
uses ldapsend
var
fldap:tldapsend;
fad_domain,ausername,apassword:string;
begin
ausername:='your AD username';
apassword:='your AD password';
fldap := TLDAPSend.Create;
fad_domain:= 'your.ad.domain';
fldap.TargetHost:=fad_domain;
//next line is the key to getting AD authentication working
fldap.UserName := ausername+'@'+fad_domain;
fldap.Password := apassword;
try
try
if fldap.Login then
if fldap.Bind then
begin
//user is succesfully authenticated at this point
end else
raise exception.Create('LDAP bind failed.');
except
on e:exception do
//whatever
end;
finally
fldap.logout;
freeandnil(fldap);
end;
end;
{code}
All the best!
Kurt
|