首页 > 解决方案 > Php ldap bind - 无法绑定到服务器:凭据无效

问题描述

我已经检查了这个问题的大量解决方案,但没有一个解决了我的问题,我正在构建一个 laravel 应用程序并且需要为此目的针对 AD 对用户进行身份验证我发现我可以使用以下脚本完成此操作

  $ldap_dn = "uid=user,dc=example,dc=local";

  $ldap_password = "somePassword";
  $ldap_con = ldap_connect("ldap://domain") or die("Could not connect to LDAP server.");

  ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ldap_con, LDAP_OPT_REFERRALS, 0);
  $bind = ldap_bind($ldap_con, $ldap_dn, $ldap_password);


  if($bind)
  {
    return "Authenticated";
  }

但是,无论我如何更改参数,我都会遇到同样的错误。这是我尝试过的事情的列表:将此行修改$ldap_dn = "uid=user,dc=example,dc=local";为:

我确信我的凭据是正确的,我已经在 C# 中对此进行了测试,并且它与以下脚本完美配合:

public static bool IsAuthenticated(string ldap, string usr, string pwd)
    {
        bool authenticated = false;

        try
        {
            DirectoryEntry entry = new DirectoryEntry(ldap, usr, pwd);
            object nativeObject = entry.NativeObject;
            authenticated = true;
        }
        catch (DirectoryServicesCOMException cex)
        {

        }
        catch (Exception ex)
        {

        }
        return authenticated;
    }

我什至尝试编译 ac# dll 以绕过 php 中的 ldap 绑定,但该解决方案也陷入了死胡同……

标签: phpbindingldapcredentials

解决方案


推荐阅读