• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ldap_addslashes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中ldap_addslashes函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_addslashes函数的具体用法?PHP ldap_addslashes怎么用?PHP ldap_addslashes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ldap_addslashes函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: test_ldap_addslashes

 public function test_ldap_addslashes()
 {
     // See http://tools.ietf.org/html/rfc4514#section-5.2 if you want
     // to add additional tests.
     $tests = array(array('test' => 'Simplest', 'expected' => 'Simplest'), array('test' => 'Simple case', 'expected' => 'Simple\\20case'), array('test' => 'Medium ‒ case', 'expected' => 'Medium\\20‒\\20case'), array('test' => '#Harder+case#', 'expected' => '\\23Harder\\2bcase\\23'), array('test' => ' Harder (and); harder case ', 'expected' => '\\20Harder\\20(and)\\3b\\20harder\\20case\\20'), array('test' => 'Really \\0 (hard) case!\\', 'expected' => 'Really\\20\\5c0\\20(hard)\\20case!\\5c'), array('test' => 'James "Jim" = Smith, III', 'expected' => 'James\\20\\22Jim\\22\\20\\3d\\20Smith\\2c\\20III'), array('test' => '  <[email protected]> ', 'expected' => '\\20\\20\\[email protected]\\3e\\20'));
     foreach ($tests as $test) {
         $this->assertSame($test['expected'], ldap_addslashes($test['test']));
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:9,代码来源:ldaplib_test.php


示例2: user_create

 /**
  * Creates a new user on LDAP.
  * By using information in userobject
  * Use user_exists to prevent duplicate usernames
  *
  * @param mixed $userobject  Moodle userobject
  * @param mixed $plainpass   Plaintext password
  */
 function user_create($userobject, $plainpass)
 {
     $extusername = core_text::convert($userobject->username, 'utf-8', $this->config->ldapencoding);
     $extpassword = core_text::convert($plainpass, 'utf-8', $this->config->ldapencoding);
     switch ($this->config->passtype) {
         case 'md5':
             $extpassword = '{MD5}' . base64_encode(pack('H*', md5($extpassword)));
             break;
         case 'sha1':
             $extpassword = '{SHA}' . base64_encode(pack('H*', sha1($extpassword)));
             break;
         case 'plaintext':
         default:
             break;
             // plaintext
     }
     $ldapconnection = $this->ldap_connect();
     $attrmap = $this->ldap_attributes();
     $newuser = array();
     foreach ($attrmap as $key => $values) {
         if (!is_array($values)) {
             $values = array($values);
         }
         foreach ($values as $value) {
             if (!empty($userobject->{$key})) {
                 $newuser[$value] = core_text::convert($userobject->{$key}, 'utf-8', $this->config->ldapencoding);
             }
         }
     }
     //Following sets all mandatory and other forced attribute values
     //User should be creted as login disabled untill email confirmation is processed
     //Feel free to add your user type and send patches to [email protected] to add them
     //Moodle distribution
     switch ($this->config->user_type) {
         case 'edir':
             $newuser['objectClass'] = array('inetOrgPerson', 'organizationalPerson', 'person', 'top');
             $newuser['uniqueId'] = $extusername;
             $newuser['logindisabled'] = 'TRUE';
             $newuser['userpassword'] = $extpassword;
             $uadd = ldap_add($ldapconnection, $this->config->user_attribute . '=' . ldap_addslashes($extusername) . ',' . $this->config->create_context, $newuser);
             break;
         case 'rfc2307':
         case 'rfc2307bis':
             // posixAccount object class forces us to specify a uidNumber
             // and a gidNumber. That is quite complicated to generate from
             // Moodle without colliding with existing numbers and without
             // race conditions. As this user is supposed to be only used
             // with Moodle (otherwise the user would exist beforehand) and
             // doesn't need to login into a operating system, we assign the
             // user the uid of user 'nobody' and gid of group 'nogroup'. In
             // addition to that, we need to specify a home directory. We
             // use the root directory ('/') as the home directory, as this
             // is the only one can always be sure exists. Finally, even if
             // it's not mandatory, we specify '/bin/false' as the login
             // shell, to prevent the user from login in at the operating
             // system level (Moodle ignores this).
             $newuser['objectClass'] = array('posixAccount', 'inetOrgPerson', 'organizationalPerson', 'person', 'top');
             $newuser['cn'] = $extusername;
             $newuser['uid'] = $extusername;
             $newuser['uidNumber'] = AUTH_UID_NOBODY;
             $newuser['gidNumber'] = AUTH_GID_NOGROUP;
             $newuser['homeDirectory'] = '/';
             $newuser['loginShell'] = '/bin/false';
             // IMPORTANT:
             // We have to create the account locked, but posixAccount has
             // no attribute to achive this reliably. So we are going to
             // modify the password in a reversable way that we can later
             // revert in user_activate().
             //
             // Beware that this can be defeated by the user if we are not
             // using MD5 or SHA-1 passwords. After all, the source code of
             // Moodle is available, and the user can see the kind of
             // modification we are doing and 'undo' it by hand (but only
             // if we are using plain text passwords).
             //
             // Also bear in mind that you need to use a binding user that
             // can create accounts and has read/write privileges on the
             // 'userPassword' attribute for this to work.
             $newuser['userPassword'] = '*' . $extpassword;
             $uadd = ldap_add($ldapconnection, $this->config->user_attribute . '=' . ldap_addslashes($extusername) . ',' . $this->config->create_context, $newuser);
             break;
         case 'ad':
             // User account creation is a two step process with AD. First you
             // create the user object, then you set the password. If you try
             // to set the password while creating the user, the operation
             // fails.
             // Passwords in Active Directory must be encoded as Unicode
             // strings (UCS-2 Little Endian format) and surrounded with
             // double quotes. See http://support.microsoft.com/?kbid=269190
             if (!function_exists('mb_convert_encoding')) {
                 print_error('auth_ldap_no_mbstring', 'auth_ldap');
             }
//.........这里部分代码省略.........
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:101,代码来源:auth.php


示例3: get_users_having_attribute_value

 function get_users_having_attribute_value($attributevalue)
 {
     global $CFG, $DB;
     //build a filter
     $filter = '(&(' . $this->config->user_attribute . '=*)' . $this->config->objectclass . ')';
     $filter = '(&' . $filter . '(' . $this->config->cohort_synching_ldap_attribute_attribute . '=' . ldap_addslashes($attributevalue) . '))';
     if ($CFG->debug_ldap_groupes) {
         pp_print_object('looking for ', $filter);
     }
     // call Moodle ldap_get_userlist that return it as an array with Moodle user attributes names
     $matchings = $this->ldap_get_userlist($filter);
     // return the FIRST entry found
     if (empty($matchings)) {
         if ($CFG->debug_ldap_groupes) {
             pp_print_object('not found', '');
         }
         return array();
     }
     if ($CFG->debug_ldap_groupes) {
         pp_print_object('found ', count($matchings) . ' matching users in LDAP');
     }
     $ret = array();
     //remove all matching LDAP users unkown to Moodle
     foreach ($matchings as $member) {
         $params = array('username' => $member);
         if ($user = $DB->get_record('user', $params, 'id,username')) {
             $ret[$user->id] = $user->username;
         }
     }
     if ($CFG->debug_ldap_groupes) {
         pp_print_object('found ', count($ret) . ' matching users known to Moodle');
     }
     return $ret;
 }
开发者ID:sb-relaxt-at,项目名称:moodle_local_ldap,代码行数:34,代码来源:locallib.php



注:本文中的ldap_addslashes函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ldap_bind函数代码示例发布时间:2022-05-15
下一篇:
PHP ldap_add函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap