PHP ldap_bind() 身份验证 - 错误无法绑定到服务器:凭据无效?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8329798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:27:17  来源:igfitidea点击:

PHP ldap_bind() authentication - error Unable to bind to server: Invalid credentials?

phpldap

提问by user840930

I'm trying to authenticate a user with LDAP using PHP. I have the DN for the user which I have checked to be correct. I also have a password. This is the correct password for the user when they authenticate with SamAccountName.

我正在尝试使用 PHP 通过 LDAP 对用户进行身份验证。我有我检查过的用户的 DN。我也有密码。这是用户使用 进行身份验证时的正确密码SamAccountName

I am hoping this is the password to use when authenticating with the DN. There isn't a Distinguished Name specific password for LDAP is there? The following is my code to authenticate using PHP's ldap_bind()function. Am I doing this correct?

我希望这是使用 DN 进行身份验证时使用的密码。没有用于 LDAP 的专有名称特定密码吗?以下是我使用 PHPldap_bind()函数进行身份验证的代码。我这样做正确吗?

$ldaphost="ldap://somehost.com:3268";
$dn = "cn=LastName\, FirstName Dept/Country/ext,OU=Accounts,OU=Location,ou=Division,";
$basedn="dc=abc,dc=enterprise";

if (!($connect = ldap_connect($ldaphost))) {    
  die ("Could not connect to LDAP server"); 
} 

$ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);

if ($ldapbind) {
   echo "LDAP bind successful...";
} else {
   echo "LDAP bind failed...";
}

The result I get from the above code is :

我从上面的代码得到的结果是:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials LDAP bind failed...

警告:ldap_bind() [function.ldap-bind]:无法绑定到服务器:无效凭据 LDAP 绑定失败...

From the line where ldap_bind()call is made:

ldap_bind()拨打电话的线路:

$ldapbind = ldap_bind($connect, "$dn" . "$basedn", $password);

Invalid credentials makes me believe there is something wrong potentially with the DN or password. I have triple checked the DN and there is not an error there as far as I can see.

无效的凭据让我相信 DN 或密码可能有问题。我已经三重检查了 DN,据我所知,那里没有错误。

Any ideas?

有任何想法吗?

回答by Stephan B

I guess you are connecting to a Microsoft Domain, you can try the domain syntax for the credentials then. For User015 in DOMAIN - DOMAIN\user015

我猜您正在连接到 Microsoft 域,然后您可以尝试凭据的域语法。对于 DOMAIN 中的 User015 - DOMAIN\user015

回答by wonza

When ever dealing with ldap I always find jxploreruseful

在处理 ldap 时,我总是发现jxplorer很有用