刚刚使用以下命令在C#中实现了AD身份验证:

DirectoryEntry entry =
  new DirectoryEntry(_path, domainAndUsername, pwd, AuthenticationTypes.Secure);


其中_path是LDAP:// +完全限定的域名(例如,域控制器的ip)。

现在,我必须使用Delphi进行相同的操作。因此,我在http://www.freemeg.com/index.php/projects/projects-2/15-delphi-ldap-authentication-component处找到了所罗门出色的Delphi 2007 LDAP实现


有没有适用于Delphi 2009+(统一码)的工作版本?
是否有人通过简单的AD身份验证处理(例如,验证)域\用户名和密码来工作?


在C#中,好处是我不需要遍历AD-我只是通过LDAP执行一级搜索-只是检查用户是否已通过身份验证。

最佳答案

Tony Caduto为我提供了Synapse解决方案:

我将这些内容从我创建的身份验证对象中删除,我不想发布整个内容,因为其中还有很多其他不相关的内容。

这应该可以帮助您,关键是用'@ your.ad.domain.name'连接AD用户名。
成功绑定后,您可以通过提供基本DN对AD目录进行搜索
并使用ldapsend单元的搜索功能。

我发现这比其他方法要快,而且很可靠。您确实需要获得的主干版本
synapse,因此它可与delphi的更高版本一起使用。

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;


谢谢托尼!

10-07 19:21
查看更多