Php ldap绑定-无法绑定到服务器:凭据无效
我已经为这个问题检查了大量的解决方案,但没有一个解决了我的问题,我正在构建一个laravel应用程序,需要根据广告验证用户。为此,我发现我可以用下面的脚本完成这项工作Php ldap绑定-无法绑定到服务器:凭据无效,php,binding,ldap,credentials,Php,Binding,Ldap,Credentials,我已经为这个问题检查了大量的解决方案,但没有一个解决了我的问题,我正在构建一个laravel应用程序,需要根据广告验证用户。为此,我发现我可以用下面的脚本完成这项工作 $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_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\u dn=“uid=user,dc=example,dc=local”代码>至:
- $ldap_dn=“cn=user,dc=example,dc=local”李>
- $ldap_dn=“uid=domain\user,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;
}
我甚至试着编译一个c#dll来绕过php中的ldap绑定,但这个解决方案也走到了死胡同…可能是因为您没有安全地连接(如AD所要求),所以密码是以明文传输的。尝试使用@timclutton作为参数传递什么?LDAP资源,即LDAP\u start\u tls($LDAP\u con)
.Hmm,我现在遇到了这个错误“无法启动TLS:服务器不可用”,现在正在测试这个解决方案,实际上,只要在本地测试,我就可以成功绑定,而无需使用ldap\u start\u TLS()
。我一定是记错了,只有在更改密码时才需要TLS。