当前位置: 首页>>代码示例>>PHP>>正文


PHP Util::generateRandomBytes方法代码示例

本文整理汇总了PHP中OCP\Util::generateRandomBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::generateRandomBytes方法的具体用法?PHP Util::generateRandomBytes怎么用?PHP Util::generateRandomBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCP\Util的用法示例。


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

示例1: post_login

 public static function post_login($parameters)
 {
     $uid = $parameters['uid'];
     $casBackend = OC_USER_CAS::getInstance();
     $userDatabase = new \OC\User\Database();
     if (phpCAS::isAuthenticated()) {
         // $cas_attributes may vary in name, therefore attributes are fetched to $attributes
         $cas_attributes = phpCAS::getAttributes();
         $cas_uid = phpCAS::getUser();
         // parameters
         $attributes = array();
         if ($cas_uid == $uid) {
             \OCP\Util::writeLog('cas', 'attr  \\"' . implode(',', $cas_attributes) . '\\" for the user: ' . $uid, \OCP\Util::DEBUG);
             if (array_key_exists($casBackend->displayNameMapping, $cas_attributes)) {
                 $attributes['cas_name'] = $cas_attributes[$casBackend->displayNameMapping];
             } else {
                 $attributes['cas_name'] = $cas_attributes['cn'];
             }
             if (array_key_exists($casBackend->mailMapping, $cas_attributes)) {
                 $attributes['cas_email'] = $cas_attributes[$casBackend->mailMapping];
             } else {
                 $attributes['cas_email'] = $cas_attributes['mail'];
             }
             if (array_key_exists($casBackend->groupMapping, $cas_attributes)) {
                 $attributes['cas_groups'] = $cas_attributes[$casBackend->groupMapping];
             } else {
                 if (!empty($casBackend->defaultGroup)) {
                     $attributes['cas_groups'] = array($casBackend->defaultGroup);
                     \OCP\Util::writeLog('cas', 'Using default group "' . $casBackend->defaultGroup . '" for the user: ' . $uid, \OCP\Util::DEBUG);
                 }
             }
             if (!$userDatabase->userExists($uid) && $casBackend->autocreate) {
                 // create users if they do not exist
                 if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
                     \OCP\Util::writeLog('cas', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', \OCP\Util::DEBUG);
                     return false;
                 } else {
                     $random_password = \OCP\Util::generateRandomBytes(20);
                     \OCP\Util::writeLog('cas', 'Creating new user: ' . $uid, \OCP\Util::DEBUG);
                     $userDatabase->createUser($uid, $random_password);
                     // after creating the user, fill the attributes
                     if ($userDatabase->userExists($uid)) {
                         OC_USER_CAS_Hooks::update_user($uid, $attributes);
                     }
                 }
             }
             // try to update user attributes
             if ($casBackend->updateUserData) {
                 OC_USER_CAS_Hooks::update_user($cas_uid, $attributes);
             }
             return true;
         }
     }
     return false;
 }
开发者ID:felixrupp,项目名称:user_cas,代码行数:55,代码来源:hooks.php

示例2: testCountWithSearchString

 public function testCountWithSearchString()
 {
     $access = $this->getAccessMock();
     $this->enableGroups($access);
     $access->expects($this->any())->method('groupname2dn')->will($this->returnValue('cn=group,dc=foo,dc=bar'));
     $access->expects($this->any())->method('fetchListOfUsers')->will($this->returnValue(array()));
     $access->expects($this->any())->method('readAttribute')->will($this->returnCallback(function ($name) {
         //the search operation will call readAttribute, thus we need
         //to anaylze the "dn". All other times we just need to return
         //something that is neither null or false, but once an array
         //with the users in the group – so we do so all other times for
         //simplicicity.
         if (strpos($name, 'u') === 0) {
             return strpos($name, '3');
         }
         return array('u11', 'u22', 'u33', 'u34');
     }));
     $access->expects($this->any())->method('dn2username')->will($this->returnCallback(function () {
         return 'foobar' . \OCP\Util::generateRandomBytes(7);
     }));
     $groupBackend = new GroupLDAP($access);
     $users = $groupBackend->countUsersInGroup('group', '3');
     $this->assertSame(2, $users);
 }
开发者ID:droiter,项目名称:openwrt-on-android,代码行数:24,代码来源:group_ldap.php

示例3: encryptPassword

 /**
  * Encrypt a single password
  *
  * @param string $password plain text password
  * @return string encrypted password
  */
 private static function encryptPassword($password)
 {
     $cipher = self::getCipher();
     $iv = \OCP\Util::generateRandomBytes(16);
     $cipher->setIV($iv);
     return base64_encode($iv . $cipher->encrypt($password));
 }
开发者ID:DaubaKao,项目名称:owncloud-core,代码行数:13,代码来源:config.php

示例4: while

* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('activity');
\OCP\JSON::callCheck();
$l = \OCP\Util::getL10N('activity');
$token = $tokenUrl = '';
if ($_POST['enable'] === 'true') {
    // Check for collisions
    $token = \OCP\Util::generateRandomBytes();
    $preferences = new \OC\Preferences(\OC_DB::getConnection());
    $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    while (!empty($conflicts)) {
        $token = \OCP\Util::generateRandomBytes();
        $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    }
    $tokenUrl = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('activity.rss', array('token' => $token)));
}
\OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'rsstoken', $token);
\OCP\JSON::success(array('data' => array('message' => $l->t('Your settings have been updated.'), 'rsslink' => $tokenUrl)));
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:31,代码来源:rssfeed.php

示例5: renameTableSchema

 /**
  * @param \Doctrine\DBAL\Schema\Table $table
  * @param string $newName
  * @return \Doctrine\DBAL\Schema\Table
  */
 protected function renameTableSchema(Table $table, $newName)
 {
     /**
      * @var \Doctrine\DBAL\Schema\Index[] $indexes
      */
     $indexes = $table->getIndexes();
     $newIndexes = array();
     foreach ($indexes as $index) {
         if ($index->isPrimary()) {
             // do not rename primary key
             $indexName = $index->getName();
         } else {
             // avoid conflicts in index names
             $indexName = 'oc_' . \OCP\Util::generateRandomBytes(13);
         }
         $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary());
     }
     // foreign keys are not supported so we just set it to an empty array
     return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions());
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:25,代码来源:migrator.php


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