Php 空密码字段启用成功的LDAP绑定
我目前正在用PHP编写第一个LDAP脚本,其中包含2个绑定。Php 空密码字段启用成功的LDAP绑定,php,binding,ldap,bind,Php,Binding,Ldap,Bind,我目前正在用PHP编写第一个LDAP脚本,其中包含2个绑定。 第一个绑定似乎工作正常,因为在成功绑定到服务器进行查询后,我将返回结果。 但是,第二个绑定使用了与初始绑定不同的distributedName结果,这给了我一些问题。 当尝试第二次绑定时,它将允许一个空密码字段与DiscrimitedName绑定。 但是,当输入错误的密码时,它将无法正确绑定。 在这种情况下,为什么空条目会绑定?谢谢你的任何线索 以下是我正在使用的代码: //begin set parameters $host = "
第一个绑定似乎工作正常,因为在成功绑定到服务器进行查询后,我将返回结果。 但是,第二个绑定使用了与初始绑定不同的distributedName结果,这给了我一些问题。 当尝试第二次绑定时,它将允许一个空密码字段与DiscrimitedName绑定。
但是,当输入错误的密码时,它将无法正确绑定。
在这种情况下,为什么空条目会绑定?谢谢你的任何线索 以下是我正在使用的代码:
//begin set parameters
$host = "*****";
$port = "3268";
$rdnUsername = "*****";//for accessing server
$rdnPassword = "*****";//for accessing server
$_connect = ldap_connect($host);
if (! $_connect) {
die ('no connection');
}
if (isset($rdnUsername) && isset($rdnPassword)) {
$args [] = $_connect;
$args [] = $rdnUsername;
$args [] = $rdnPassword;
}
if ( ! call_user_func_array ( 'ldap_bind', $args ) ) {
die (
sprintf('Could not bind to server %s. Returned Error was: [%s] %s',$host,ldap_errno($_connect),ldap_error($_connect))
);
}
if (! isset($filter)) {
$filter = "(userPrincipalName=".$_POST['username']."@school.edu)";
}
$trimmerdUsername = trim(preg_replace('/[^a-zA-Z0-9\-\_@\.]/', '', $_POST['username']));
$filter = str_replace($_POST['username'], $trimmerdUsername, $filter);
$attributes = array("name", "telephonenumber", "mail", "userprincipalname");
$ldap_dn = "dc=tcw,dc=net,dc=tceo,dc=edu";
$_ldapresults = ldap_search($_connect, $ldap_dn, $filter, $attributes, 0, 0, 10 ) or exit("Unable to search");
if (! $_ldapresults) {
die ('No user with that information found');
}
if (1 > ldap_count_entries($_connect, $_ldapresults)) {
die ('No user with that information found');
}
if (1 < ldap_count_entries($_connect, $_ldapresults )) {
die ('More than one user found with that information');
}
$_results = ldap_get_entries($_connect, $_ldapresults);
if (false === $_results) {
die ('no result set found');
}
ldap_free_result ( $_ldapresults );
$distinguishedName = $_results[0]['dn'];
$userPrincipalName = $_results[0]["userprincipalname"][0];
print "<pre>";
print_r ($_results);
print "</pre>";
echo "<br>userPrincipalName is: ".$userPrincipalName."<br>";
echo "<br>distinguishedName is: ".$distinguishedName."<br>";
$password = $_POST['password'];
$link_id = @ldap_bind($_connect, $distinguishedName, $password);
//if (false === $link_id) {
if ($link_id === false) {
die ('BIND failed');
}else{
echo "<br>success!<br>";
}
//开始设置参数
$host=“*******”;
$port=“3268”;
$rdName=“*******”//用于访问服务器
$rdnPassword=“*******”//用于访问服务器
$\u connect=ldap\u connect($host);
如果(!$\u连接){
模具(“无连接”);
}
if(isset($rdName)&&isset($rdPassword)){
$args[]=$\u connect;
$args[]=$rdname;
$args[]=$rdpassword;
}
if(!call_user_func_数组('ldap_bind',$args)){
死(
sprintf('无法绑定到服务器%s。返回的错误为:[%s]%s',$host,ldap\u errno($\u connect),ldap\u Error($\u connect))
);
}
如果(!isset($filter)){
$filter=“(userPrincipalName=“.$\u POST['username']。”@school.edu)”;
}
$trimmerdUsername=修剪(更换前('/[^a-zA-Z0-9\-\\\\\.]/','',$张贴['username');
$filter=str_replace($_POST['username'],$trimmerdUsername,$filter);
$attributes=数组(“名称”、“电话号码”、“邮件”、“用户名”);
$ldap_dn=“dc=tcw,dc=net,dc=tceo,dc=edu”;
$\u ldapresults=ldap\u搜索($\u连接,$ldap\u dn,$filter,$attributes,0,0,10)或退出(“无法搜索”);
如果(!$\u ldapresults){
die('没有找到该信息的用户');
}
如果(1>ldap\u count\u条目($\u connect,$\u ldapresults)){
die(“未找到具有该信息的用户”);
}
如果(1userPrincipalName是:“.$userPrincipalName。”
”;
echo“
DifferentizedName是:“.$DifferentizedName。”
”;
$password=$_POST['password'];
$link\u id=@ldap\u-bind($\u-connect,$distributedname,$password);
//if(false==$link\u id){
如果($link_id==false){
die(‘绑定失败’);
}否则{
回声“
成功!
”;
}
无密码ldap匿名绑定
这是协议中定义的,应用程序要求不允许使用空密码绑定
这也记录在PHP()的ldap_bind文档中。无密码ldap匿名绑定 这是协议中定义的,应用程序要求不允许使用空密码绑定
这也记录在PHP()的ldap_bind文档中您应该避免从应用程序匿名连接到LDAP服务器,因为您不能依赖服务器配置。但是,如果您有权访问服务器,您可以通过限制访问来控制对条目的访问。在slapd.conf中添加这些行 通过匿名身份验证访问*
要了解有关访问控制的更多信息:您应该避免从应用程序匿名连接到LDAP服务器,因为您不能依赖服务器配置。但是,如果您可以访问服务器,则可以通过限制访问来控制对条目的访问。在slapd.conf中添加这些行 通过匿名身份验证访问* 要了解有关访问控制的更多信息,请执行以下操作: