php - 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";
为:
- $ldap_dn = " cn =user,dc=example,dc=local";
- $ldap_dn = "uid=域\用户,dc=example,dc=local";
- $ldap_dn = " sAMAccountName =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 绑定,但该解决方案也陷入了死胡同……
解决方案
推荐阅读
- android - 如何将图像从 Odoo 11 上传到 Android 应用程序?
- sql - 两个日期之间的工作日与日历表
- php - 在 laravel 中包含 js 文件的最佳方法是什么?
- java - 允许两个类共享变量和方法
- angular - 使用嵌套订阅返回布尔值的函数
- bash - 生成命令(unimrcp 客户端)的 Unix shell 脚本不返回
- javascript - 为什么来自 nextElementSibling.tagName 的 TypeError?
- java - Java- 使用多个测试用例和每个测试用例中的多个值扫描以下输入的代码片段
- jquery - CTRL + P 打印不超过 1 页
- html - 未从 HTML 表单中的移动浏览器中为 Tab/Next 键发出 Keydown 事件