EdZava / VCL-ActiveDirectory4Delphi

Delphi basic library for validation and authentication of LDAP users in Active Directory.
MIT License
82 stars 14 forks source link

autenticação feita com um usuario senha e dominio #4

Closed mathst closed 1 year ago

mathst commented 1 year ago

I didn't find a simple way to authenticate, I think it's the simplest way and if possible with the port too

EdZava commented 1 year ago

@mathst Voce conseguiu fazer a autenticacao ? Chego a testar a app do exemplo ?

mathst commented 1 year ago

(pt-br)desculpa a pergunta, é que o exemplo esta com um pequeno contexto diferente e me confundi no começo, mas depois entendi como realizaria.

como eu utilizei:

(en)Sorry for the question, it's just that the example is with a little different context and I got confused at first, but then I understood how it would be done.

how i used it:

procedure Tfrm_Auth.FormCreate(Sender: TObject);
begin
  // Separate Window
  SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
end;

procedure Tfrm_Auth.Button1Click(Sender: TObject);
begin
  if ActiveDirectoryClient.AuthenticateUser('0.0.0.0', Edit1.Text, Edit2.Text) then
  begin
    ShowMessage('Sucesso na autenticação');
    FAuthSuccessful := True; // Autenticação bem-sucedida
    ModalResult := mrOk; // Fecha o formulário de autenticação
  end
  else
  begin
    ShowMessage('Falha na autenticação,usuario ou senha incorreto.');
    FAuthSuccessful := False; // Autenticação falhou
    ModalResult := mrCancel;
  end;
end;

end.
begin
  Application.Initialize;

  Application.MainFormOnTaskbar := True;
  // Cria manualmente o formulário de autenticação
  frm_Auth := Tfrm_Auth.Create(Application);
  try
    // Exibe o formulário de autenticação e aguarda sua conclusão
    if frm_Auth.ShowModal = mrOK then
    begin
      // Verifica se a autenticação foi bem-sucedida
      // Se sim, cria e exibe o formulário principal
      Application.CreateForm(Tfrm_Main, frm_Main); // form principal

      // Agora inicie o loop de mensagens do aplicativo
      Application.Run;
      frm_Auth.Free; //limpa o form de auth
    end;
  finally
    frm_Auth.Free; // Libera o formulário de autenticação quando não é mais necessário
  end;
end.