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


PHP Security\ISecureRandom类代码示例

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


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

示例1: sendEmail

 /**
  * @param string $user
  * @throws \Exception
  */
 protected function sendEmail($user)
 {
     if (!$this->userManager->userExists($user)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
     }
     $email = $this->config->getUserValue($user, 'settings', 'email');
     if (empty($email)) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.'));
     }
     $token = $this->secureRandom->getMediumStrengthGenerator()->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
     $this->config->setUserValue($user, 'owncloud', 'lostpassword', $token);
     $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token));
     $tmpl = new \OC_Template('core/lostpassword', 'email');
     $tmpl->assign('link', $link, false);
     $msg = $tmpl->fetchPage();
     try {
         $message = $this->mailer->createMessage();
         $message->setTo([$email => $user]);
         $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
         $message->setPlainBody($msg);
         $message->setFrom([$this->from => $this->defaults->getName()]);
         $this->mailer->send($message);
     } catch (\Exception $e) {
         throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
     }
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:30,代码来源:lostcontroller.php

示例2: __construct

 /**
  * @param IConfig $config
  * @param ICrypto $crypto
  * @param ISecureRandom $random
  * @param IRequest $request
  */
 public function __construct(IConfig $config, ICrypto $crypto, ISecureRandom $random, IRequest $request)
 {
     $this->crypto = $crypto;
     $this->config = $config;
     $this->random = $random;
     if (!is_null($request->getCookie(self::COOKIE_NAME))) {
         $this->passphrase = $request->getCookie(self::COOKIE_NAME);
     } else {
         $this->passphrase = $this->random->getMediumStrengthGenerator()->generate(128);
         $secureCookie = $request->getServerProtocol() === 'https';
         // FIXME: Required for CI
         if (!defined('PHPUNIT_RUN')) {
             setcookie(self::COOKIE_NAME, $this->passphrase, 0, \OC::$WEBROOT, '', $secureCookie, true);
         }
     }
 }
开发者ID:rosarion,项目名称:core,代码行数:22,代码来源:cryptowrapper.php

示例3: testGetIdWithoutModUnique

 public function testGetIdWithoutModUnique()
 {
     $lowRandomSource = $this->getMockBuilder('\\OCP\\Security\\ISecureRandom')->disableOriginalConstructor()->getMock();
     $lowRandomSource->expects($this->once())->method('generate')->with('20')->will($this->returnValue('GeneratedByOwnCloudItself'));
     $this->secureRandom->expects($this->once())->method('getLowStrengthGenerator')->will($this->returnValue($lowRandomSource));
     $request = new Request([], $this->secureRandom, $this->getMock('\\OCP\\Security\\ICrypto'), $this->config, $this->stream);
     $this->assertSame('GeneratedByOwnCloudItself', $request->getId());
 }
开发者ID:rosarion,项目名称:core,代码行数:8,代码来源:RequestTest.php

示例4: createShare

 /**
  * Share a path
  *
  * @param \OCP\Share\IShare $share
  * @return Share The share object
  * @throws \Exception
  *
  * TODO: handle link share permissions or check them
  */
 public function createShare(\OCP\Share\IShare $share)
 {
     if (!$this->canShare($share)) {
         throw new \Exception('The Share API is disabled');
     }
     $this->generalCreateChecks($share);
     //Verify share type
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         $this->userCreateChecks($share);
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             $this->groupCreateChecks($share);
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 $this->linkCreateChecks($share);
                 $this->setLinkParent($share);
                 /*
                  * For now ignore a set token.
                  */
                 $share->setToken($this->secureRandom->generate(\OC\Share\Constants::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS));
                 //Verify the expiration date
                 $this->validateExpirationDate($share);
                 //Verify the password
                 $this->verifyPassword($share->getPassword());
                 // If a password is set. Hash it!
                 if ($share->getPassword() !== null) {
                     $share->setPassword($this->hasher->hash($share->getPassword()));
                 }
             }
         }
     }
     // Verify if there are any issues with the path
     $this->pathCreateChecks($share->getNode());
     // On creation of a share the owner is always the owner of the path
     $share->setShareOwner($share->getNode()->getOwner()->getUID());
     // Cannot share with the owner
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $share->getShareOwner()) {
         throw new \InvalidArgumentException('Can\'t share with the share owner');
     }
     // Generate the target
     $target = $this->config->getSystemValue('share_folder', '/') . '/' . $share->getNode()->getName();
     $target = \OC\Files\Filesystem::normalizePath($target);
     $share->setTarget($target);
     // Pre share hook
     $run = true;
     $error = '';
     $preHookData = ['itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemSource' => $share->getNode()->getId(), 'shareType' => $share->getShareType(), 'uidOwner' => $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'fileSource' => $share->getNode()->getId(), 'expiration' => $share->getExpirationDate(), 'token' => $share->getToken(), 'itemTarget' => $share->getTarget(), 'shareWith' => $share->getSharedWith(), 'run' => &$run, 'error' => &$error];
     \OC_Hook::emit('OCP\\Share', 'pre_shared', $preHookData);
     if ($run === false) {
         throw new \Exception($error);
     }
     $provider = $this->factory->getProviderForType($share->getShareType());
     $share = $provider->create($share);
     // Post share hook
     $postHookData = ['itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', 'itemSource' => $share->getNode()->getId(), 'shareType' => $share->getShareType(), 'uidOwner' => $share->getSharedBy(), 'permissions' => $share->getPermissions(), 'fileSource' => $share->getNode()->getId(), 'expiration' => $share->getExpirationDate(), 'token' => $share->getToken(), 'id' => $share->getId(), 'shareWith' => $share->getSharedWith(), 'itemTarget' => $share->getTarget(), 'fileTarget' => $share->getTarget()];
     \OC_Hook::emit('OCP\\Share', 'post_shared', $postHookData);
     return $share;
 }
开发者ID:ZverAleksey,项目名称:core,代码行数:67,代码来源:manager.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 = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER);
         }
         $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:drognisep,项目名称:Portfolio-Site,代码行数:25,代码来源:Migrator.php

示例6: generateToken

 /**
  * generate to token used to authenticate federated shares
  *
  * @return string
  */
 public function generateToken()
 {
     $token = $this->secureRandom->generate(self::TOKEN_LENGTH, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
     return $token;
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:10,代码来源:TokenHandler.php

示例7: save

 public function save($email)
 {
     $query = $this->db->prepareQuery('INSERT INTO `*PREFIX*registration`' . ' ( `email`, `token`, `requested` ) VALUES( ?, ?, NOW() )');
     $token = $this->random->generate(30);
     $query->execute(array($email, $token));
     return $token;
 }
开发者ID:WeatherellTechnology,项目名称:weatherstorm7,代码行数:7,代码来源:pendingregist.php

示例8: testCreateCredentials

 public function testCreateCredentials()
 {
     $this->jobList->expects($this->once())->method('add')->with('OCA\\UpdateNotification\\ResetTokenBackgroundJob');
     $this->secureRandom->expects($this->once())->method('generate')->with(64)->willReturn('MyGeneratedToken');
     $this->config->expects($this->once())->method('setSystemValue')->with('updater.secret');
     $this->timeFactory->expects($this->once())->method('getTime')->willReturn(12345);
     $this->config->expects($this->once())->method('setAppValue')->with('core', 'updater.secret.created', 12345);
     $expected = new DataResponse('MyGeneratedToken');
     $this->assertEquals($expected, $this->adminController->createCredentials());
 }
开发者ID:ZverAleksey,项目名称:core,代码行数:10,代码来源:AdminControllerTest.php

示例9: createCredentials

 /**
  * @return DataResponse
  */
 public function createCredentials()
 {
     // Create a new job and store the creation date
     $this->jobList->add('OCA\\UpdateNotification\\ResetTokenBackgroundJob');
     $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());
     // Create a new token
     $newToken = $this->secureRandom->generate(64);
     $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT));
     return new DataResponse($newToken);
 }
开发者ID:ZverAleksey,项目名称:core,代码行数:13,代码来源:admincontroller.php

示例10: addServer

 /**
  * add server to the list of trusted ownCloud servers
  *
  * @param $url
  * @return int server id
  */
 public function addServer($url)
 {
     $url = $this->updateProtocol($url);
     $result = $this->dbHandler->addServer($url);
     if ($result) {
         $token = $this->secureRandom->generate(16);
         $this->dbHandler->addToken($url, $token);
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\RequestSharedSecret', ['url' => $url, 'token' => $token]);
     }
     return $result;
 }
开发者ID:ZverAleksey,项目名称:core,代码行数:17,代码来源:trustedservers.php

示例11: encrypt

 /**
  * Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
  * @param string $plaintext
  * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
  * @return string Authenticated ciphertext
  */
 public function encrypt($plaintext, $password = '')
 {
     if ($password === '') {
         $password = $this->config->getSystemValue('secret');
     }
     $this->cipher->setPassword($password);
     $iv = $this->random->getLowStrengthGenerator()->generate($this->ivLength);
     $this->cipher->setIV($iv);
     $ciphertext = bin2hex($this->cipher->encrypt($plaintext));
     $hmac = bin2hex($this->calculateHMAC($ciphertext . $iv, $password));
     return $ciphertext . '|' . $iv . '|' . $hmac;
 }
开发者ID:dennisgermany,项目名称:core,代码行数:18,代码来源:crypto.php

示例12: generateRandomDeviceToken

 /**
  * Return a 20 digit device password
  *
  * Example: ABCDE-FGHIJ-KLMNO-PQRST
  *
  * @return string
  */
 private function generateRandomDeviceToken()
 {
     $groups = [];
     for ($i = 0; $i < 4; $i++) {
         $groups[] = $this->random->generate(5, implode('', range('A', 'Z')));
     }
     return implode('-', $groups);
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:15,代码来源:AuthSettingsController.php

示例13: getId

 /**
  * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  * If `mod_unique_id` is installed this value will be taken.
  * @return string
  */
 public function getId()
 {
     if (isset($this->server['UNIQUE_ID'])) {
         return $this->server['UNIQUE_ID'];
     }
     if (empty($this->requestId)) {
         $this->requestId = $this->secureRandom->getLowStrengthGenerator()->generate(20);
     }
     return $this->requestId;
 }
开发者ID:0x17de,项目名称:core,代码行数:15,代码来源:request.php

示例14: getSharedSecret

 /**
  * create shared secret and return it
  *
  * @return \OC_OCS_Result
  */
 public function getSharedSecret()
 {
     $url = $this->request->getParam('url');
     $token = $this->request->getParam('token');
     if ($this->trustedServers->isTrustedServer($url) === false || $this->isValidToken($url, $token) === false) {
         return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
     }
     $sharedSecret = $this->secureRandom->getMediumStrengthGenerator()->generate(32);
     $this->trustedServers->addSharedSecret($url, $sharedSecret);
     // reset token after the exchange of the shared secret was successful
     $this->dbHandler->addToken($url, '');
     return new \OC_OCS_Result(['sharedSecret' => $sharedSecret], Http::STATUS_OK);
 }
开发者ID:mrjoshuap,项目名称:core,代码行数:18,代码来源:ocsauthapi.php

示例15: feed

 /**
  * @NoAdminRequired
  *
  * @param string $enable	'true' if the feed is enabled
  * @return DataResponse
  */
 public function feed($enable)
 {
     $token = $tokenUrl = '';
     if ($enable === 'true') {
         $conflicts = true;
         // Check for collisions
         while (!empty($conflicts)) {
             $token = $this->random->generate(30);
             $conflicts = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
         }
         $tokenUrl = $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show', ['token' => $token]);
     }
     $this->config->setUserValue($this->user, 'activity', 'rsstoken', $token);
     return new DataResponse(array('data' => array('message' => (string) $this->l10n->t('Your settings have been updated.'), 'rsslink' => $tokenUrl)));
 }
开发者ID:samj1912,项目名称:repo,代码行数:21,代码来源:settings.php


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