Jump to content

Recommended Posts

Posted

unit U_Funcao_valida_senha;

interface

uses
Forms, SysUtils, Dialogs, ADODB, ActiveX;

function validasenha(usuario, senha: string): Boolean;

implementation

uses
SqlExpr, MainModule;

function validasenha(usuario, senha: string): Boolean;
var
SQLQuery : TSQLQuery;
ADOConnection : TADOConnection;
ADOQuery : TADOQuery;
begin
{Conexão Active Directory}
if Trim(SQLQuery.Fields[0].AsString) = 'AUTENTICAÇÃO ACTIVE DIRECTORY' then
begin
try
try
CoInitialize(nil);
ADOConnection := TADOConnection.Create(Application);
ADOConnection.ConnectionString:= 'Provider=ADSDSOObject;User Id='+usuario+'@domain.com.br;Password='+senha+';';
ADOConnection.Mode := cmRead;
ADOConnection.Provider := 'ADsDSOObject';
ADOConnection.LoginPrompt := False;
ADOConnection.Connected := True;

ADOQuery := TADOQuery.Create(Application);
ADOQuery.Connection := ADOConnection;
ADOQuery.CursorType := ctStatic;
ADOQuery.SQL.Clear;
ADOQuery.Close;
ADOQuery.SQL.Add('SELECT SamAccountName, Name, loginlogix '+
' FROM ''LDAP:/domain.com.br'' '+
' WHERE objectClass= ''user'' '+
' AND SamAccountName = '''+usuario+''' ');
ADOQuery.Open;
if ADOQuery.FieldByName('loginlogix').AsString = EmptyStr then
begin
ShowMessage('Usuário '+usuario+' Não Possui Usuario do Logix Cadastrado no Active Directory '+#13+
'Favor Contatar o Administrador de Sistemas.');
Result := False;
Exit;
end
else
begin
ID.glo_usuario := Trim(ADOQuery.FieldByName('loginlogix').AsString);
Result := True;
Exit;
end;

except
Result := False;
end;

finally
CoUninitialize;
FreeAndNil(ADOConnection);
FreeAndNil(ADOQuery);
end;
end;

finally
FreeAndNil(SQLQuery);
end;
end;
end;
  • Upvote 1
  • 2 years later...
Posted

Hi guys

 

I'm using LDAP authentication too. Firstly I was using LDAPAdmin but it seems this project was abandoned and doesn't work for 64 bits. So I decided to find other solution which was Ararat Synapse and works perfect in 64 bits, very light and easy to use. Here is an example:

function TUniLoginForm1.LDAPAuth(AUsername, APassword: String): Boolean;
var
  LLdap: TLDAPsend;
begin
  Result := false;
  LLdap := TLDAPsend.Create;
  try
    LLdap.TargetHost := 'ldap_server_name_or_ip';
    if not AUsuario.ToLower.StartsWith('domainname') then
      AUsuario := Format('domainname\%s', [AUsername.ToLower]);
    LLdap.UserName := AUsername;
    LLdap.Password := APassword;
    LLdap.Login;
    Result := LLdap.Bind;
  finally
    LLdap.Free;
  end;
end;

The official LDAP sample is here

Posted

Hi guys

 

I'm using LDAP authentication too. Firstly I was using LDAPAdmin but it seems this project was abandoned and doesn't work for 64 bits. So I decided to find other solution which was Ararat Synapse and works perfect in 64 bits, very light and easy to use. Here is an example:

function TUniLoginForm1.LDAPAuth(AUsername, APassword: String): Boolean;
var
  LLdap: TLDAPsend;
begin
  Result := false;
  LLdap := TLDAPsend.Create;
  try
    LLdap.TargetHost := 'ldap_server_name_or_ip';
    if not AUsuario.ToLower.StartsWith('domainname') then
      AUsuario := Format('domainname\%s', [AUsername.ToLower]);
    LLdap.UserName := AUsername;
    LLdap.Password := APassword;
    LLdap.Login;
    Result := LLdap.Bind;
  finally
    LLdap.Free;
  end;
end;

The official LDAP sample is here

 

Thanks for sharing.

 

the project Ararat Synapse has features that I needed. ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...