<legend id='2BMVD'><style id='2BMVD'><dir id='2BMVD'><q id='2BMVD'></q></dir></style></legend>
    <i id='2BMVD'><tr id='2BMVD'><dt id='2BMVD'><q id='2BMVD'><span id='2BMVD'><b id='2BMVD'><form id='2BMVD'><ins id='2BMVD'></ins><ul id='2BMVD'></ul><sub id='2BMVD'></sub></form><legend id='2BMVD'></legend><bdo id='2BMVD'><pre id='2BMVD'><center id='2BMVD'></center></pre></bdo></b><th id='2BMVD'></th></span></q></dt></tr></i><div id='2BMVD'><tfoot id='2BMVD'></tfoot><dl id='2BMVD'><fieldset id='2BMVD'></fieldset></dl></div>
  • <tfoot id='2BMVD'></tfoot>
      <bdo id='2BMVD'></bdo><ul id='2BMVD'></ul>

    1. <small id='2BMVD'></small><noframes id='2BMVD'>

        从 PHP 使用 LDAP 对用户进行身份验证

        时间:2024-08-23
            <bdo id='JjZou'></bdo><ul id='JjZou'></ul>

                <tbody id='JjZou'></tbody>

            • <legend id='JjZou'><style id='JjZou'><dir id='JjZou'><q id='JjZou'></q></dir></style></legend>

              1. <i id='JjZou'><tr id='JjZou'><dt id='JjZou'><q id='JjZou'><span id='JjZou'><b id='JjZou'><form id='JjZou'><ins id='JjZou'></ins><ul id='JjZou'></ul><sub id='JjZou'></sub></form><legend id='JjZou'></legend><bdo id='JjZou'><pre id='JjZou'><center id='JjZou'></center></pre></bdo></b><th id='JjZou'></th></span></q></dt></tr></i><div id='JjZou'><tfoot id='JjZou'></tfoot><dl id='JjZou'><fieldset id='JjZou'></fieldset></dl></div>

                <small id='JjZou'></small><noframes id='JjZou'>

                <tfoot id='JjZou'></tfoot>

                1. 本文介绍了从 PHP 使用 LDAP 对用户进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的项目是为我们大学制作一个模块招生系统.因此,我联系了我大学的 IT 人员以获取详细信息,以将学生身份验证到系统中.我们正在使用现有的大学登录开发系统.他们给了我一些 LDAP 信息,我不知道它的用途.我在 Apacha 服务器上使用 PHP、Mysql.给定用户 ID 和密码以及 LDAP 信息,我如何验证登录系统的用户.

                  My project is to make a module enrollment system for our university. So I contacted the IT people in my university for details to authenticate the students into the system. We are developing the system using the existing university login. They gave me some LDAP information, I don't know the usage of that. I'm using PHP,Mysql on an Apacha server. How can I authenticate a user logging into my system, given his userid and password with the LDAP information.

                  以下是 LDAP 信息(我已经更改了域名等)

                  Given below is the LDAP information(i have changed the domain name etc.)

                  blueroom.ac.uk 域的 LDAP 信息

                  LDAP information for blueroom.ac.uk domain

                  LDAP Host : ad.blueroom.ac.uk
                  
                  LDAP port no: 389
                  
                  BASE DN : ou=bluebird, dc=bluebird, dc=ac, dc=my
                  
                  LDAP account to bind : cn = kikdap, ou=servacc, dc=bluebird,dc=ac,dc=uk
                  
                  LDAP account password : ********
                  
                  Attribute : sAMAccountName 
                  

                  推荐答案

                  一般流程是(括号内是相关的ext/ldap php命令):

                  The general procedure would be (relevant ext/ldap php commands in brackets):

                  1. 使用LDAP 主机"和LDAP 端口号"连接到 LDAP 服务器(ldap_connect()) 并设置正确的连接选项 (ldap_set_option()),尤其是 LDAP_OPT_PROTOCOL_VERSIONLDAP_OPT_REFERRALS

                  1. connect to LDAP server using the "LDAP Host" and "LDAP port no" (ldap_connect()) and set the correct connection options (ldap_set_option()), especially LDAP_OPT_PROTOCOL_VERSION and LDAP_OPT_REFERRALS

                  使用要绑定的LDAP帐户"和LDAP帐户密码"(ldap_bind()) - 如果您针对 Active Directory 服务器进行身份验证,您可以直接使用登录页面中的用户名和密码并跳过以下所有步骤.

                  bind to LDAP server using the "LDAP account to bind" and "LDAP account password" (ldap_bind()) - if you're authenticating against an Active Directory server you can directly use the username and password from the login page and skip all the following steps.

                  通过指定BASE DN"和适当的 LDAP 过滤器在树中搜索匹配的用户条目/对象 - 很可能类似于 (&(objectClass=user)(sAMAccountName=%s)) 其中 %s 应替换为要验证的用户名 (ldap_search())

                  search the tree for a matching user entry/object by specifing the "BASE DN" and the appropriate LDAP filter - most likely something like (&(objectClass=user)(sAMAccountName=%s)) where %s should be replaced by the username to be authenticated (ldap_search())

                  检查返回的条目数是否为 1(如果 <> 1 则表示出现问题,例如未找到用户或找到多个用户)

                  check if the number of returned entries is 1 (if <> 1 then something has gone wrong, e.g. no user found or multiple users found)

                  检索此单个条目的可分辨名称 (DN) (ldap_get_dn())

                  retrive the distinguished name (DN) of this single entry (ldap_get_dn())

                  使用在上一步中找到的 DN 尝试使用身份验证页面上提供的密码绑定到 LDAP 服务器 (ldap_bind())

                  use the DN found in the last step to try to bind to the LDAP server with the password given at the authentication page (ldap_bind())

                  如果绑定成功则一切正常,如果不成功,很可能是密码错误

                  if the bind succeeds then everything is OK, if not, most likely the password is wrong

                  这真的不像一开始听起来那么难.一般来说,我建议使用某种标准库来针对 LDAP 服务器进行身份验证,例如 Net_LDAP2 PEAR 包或 Zend_Ldap 脱离 Zend 框架.我没有实际使用 Net_LDAP2 的经验(尽管我非常了解代码),但 Zend_Ldap 对 Active Directory 服务器或 ADAMS 服务器非常有效(这显然是你的正在使用).

                  It's really not as hard as it sounds at first. Generally I'd propose to use some sort of standard library for authenticating against a LDAP server such as the Net_LDAP2 PEAR package or Zend_Ldap out of the Zend Framework. I have no experience with actually using Net_LDAP2 (although I know the code quite well) but Zend_Ldap works very well against Active Directory servers or ADAMS servers (which is obviously what you're working with).

                  这将使用 Zend_Ldap 解决问题:

                  This will do the trick using Zend_Ldap:

                  $options = array(
                      'host'                 => 'ad.blueroom.ac.uk',
                      'useStartTls'          => true,
                      'accountDomainName'    => 'blueroom.ac.uk',
                      'accountCanonicalForm' => 4,
                      'baseDn'               => 'ou=bluebird,dc=bluebird,dc=ac,dc=my',
                  );
                  $ldap = new Zend_Ldap($options);
                  try {
                      $ldap->bind('user', 'password');
                  } catch (Zend_Ldap_Exception $e) {
                      // something failed - inspect $e
                  }
                  // bind successful
                  $acctname = $ldap->getCanonicalAccountName('user', Zend_Ldap::ACCTNAME_FORM_DN);
                  

                  这篇关于从 PHP 使用 LDAP 对用户进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:LDAP 操作错误 下一篇:即使我编辑了 php.ini 并且 php_ldap.dll 在正确的位置,也无法启用 PHP LDAP?

                  相关文章

                  1. <small id='lHIr6'></small><noframes id='lHIr6'>

                      <bdo id='lHIr6'></bdo><ul id='lHIr6'></ul>
                  2. <i id='lHIr6'><tr id='lHIr6'><dt id='lHIr6'><q id='lHIr6'><span id='lHIr6'><b id='lHIr6'><form id='lHIr6'><ins id='lHIr6'></ins><ul id='lHIr6'></ul><sub id='lHIr6'></sub></form><legend id='lHIr6'></legend><bdo id='lHIr6'><pre id='lHIr6'><center id='lHIr6'></center></pre></bdo></b><th id='lHIr6'></th></span></q></dt></tr></i><div id='lHIr6'><tfoot id='lHIr6'></tfoot><dl id='lHIr6'><fieldset id='lHIr6'></fieldset></dl></div>

                    <tfoot id='lHIr6'></tfoot>

                      <legend id='lHIr6'><style id='lHIr6'><dir id='lHIr6'><q id='lHIr6'></q></dir></style></legend>