📄 ldapauthlib.pas
字号:
unit ldapauthlib;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ldapclasses, StdCtrls;
var
LDAPSession:TLDAPSession;
LDAPEntryList:TLDAPEntryList;
SearchCallBack:TSearchCallback;
implementation
{$R *.dfm}
procedure SetLDAPServer(server:string;port:integer;ldapVersion:integer;TLS:boolean;tcpport:integer;anonymousbind:boolean;bindusername:string;bindpassword:string;baseDN:string;MicrosoftAD:boolean;
function AuthLDAPUser(authusername:string,authpassword:string
var e:array[0..0] of string;
i:integer;
begin
LDAPSession := TLDAPSession.Create;
LDAPEntryList := TLDAPEntryList.create;
LDAPSession.Server := '192.168.2.10';
LDAPSession.Base := 'dc=ad,dc=freemeg,dc=com';
LDAPSESSION.PagedSearch := TRUE;
LDAPSEssion.PageSize := 100;
LDAPSession.SSL := false;
LDAPSession.DereferenceAliases := 0;
LDAPSession.Version := 3;
LDAPSEssion.AuthMethod := 0;
// LDAPSession.User := 'cn=administrator,dc=ad,dc=freemeg,dc=com';
LDAPSession.User := 'administrator@ad.freemeg.com';
LDAPSession.Password := 'solfi25/3';
LdapSession.ChaseReferrals := true;
ldapsession.ReferralHops := 32;
LDAPSession.Connect;
e[0] := 'cn';
if ldapsession.Connected then
begin
memo1.Lines.add('Connected');
LDAPSession.Search('cn=solb','dc=ad,dc=freemeg,dc=com',2,e,TRUE,LdapENtrylist, SearchCallBack);
memo1.Lines.Add(ldapentrylist.Items[0].dn );
ldapentrylist.Items[0].Read;
if ldapentrylist.Count > 0 then
begin
LDAPSession.Disconnect;
try
memo1.Lines.Add(ldapentrylist.Items[0].AttributesbyName['cn'].Values[0].AsString );
//Other
LDAPSession.User := LDAPEntrylist.Items[0].dn;
//MS // LDAPSession.User := LDAPEntrylist.Items[0].AttributesByName['cn'].AsString + '@ad.freemeg.com';
LDAPSession.Password := 'foxhunt';
LDAPSession.Connect;
if LDAPSession.connected then
begin
memo1.lines.add('Yes');
ldapentrylist.Items[0].Read;
end;
except
on e:exception do
SHowmessage('Sorry Bad something');
end;
end;
end
else memo1.lines.add('Failed to Connect');
// LDAPSession.Search('','dc=freemeg.com',0,'uid',0,LdapEntryList,SearchCallBack);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -