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


PHP Random::generate方法代码示例

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


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

示例1: generateToken

 /**
  * @return string
  */
 private function generateToken($random = NULL)
 {
     if ($random === NULL) {
         $random = Nette\Utils\Random::generate(10);
     }
     return $random . base64_encode(sha1($this->getToken() . $random, TRUE));
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:10,代码来源:CsrfProtection.php

示例2: create

 public function create(Product $product, FileUpload $fileUpload)
 {
     switch ($fileUpload->getContentType()) {
         case 'image/jpeg':
             $suffix = 'jpg';
             break;
         case 'image/png':
             $suffix = 'png';
             break;
         case 'image/gif':
             $suffix = 'gif';
             break;
         default:
             throw new EntityInvalidArgumentException(sprintf('File is of an unknown type %s.', $fileUpload->getContentType()));
     }
     $baseName = sprintf('%s-%%s.%s', Strings::webalize($product->getName()), $suffix);
     do {
         $fileName = sprintf($baseName, Random::generate(5, '0-9a-zA-Z'));
         $path = sprintf('%s/%s', $this->imagesDir, $fileName);
     } while (file_exists($path));
     $fileUpload->move($path);
     $image = new ProductImage($product, $fileName);
     $this->createEntity($image);
     $product->addImage($image);
     return $image;
 }
开发者ID:shophp,项目名称:shophp,代码行数:26,代码来源:ProductImageService.php

示例3: formSucceeded

 /**
  * Callback for ForgottenPasswordForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     $user = $this->userManager->findByEmail($values->email);
     if (!$user) {
         $form->addError('No user with given email found');
         return;
     }
     $password = Nette\Utils\Random::generate(10);
     $this->userManager->setNewPassword($user->id, $password);
     try {
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $mail = new Nette\Mail\Message();
         $mail->setFrom('noreply@notejamapp.com', 'Notejamapp');
         $mail->addTo($user->email);
         $mail->setSubject('New notejam password');
         $mail->setBody(sprintf('Your new password: %s', $password));
         $this->mailer->send($mail);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, Debugger::EXCEPTION);
         $form->addError('Could not send email with new password');
     }
 }
开发者ID:martinmayer,项目名称:notejam,代码行数:30,代码来源:ForgottenPasswordFormFactory.php

示例4: sendFormSucceeded

 function sendFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
 {
     $email = $form->getValues()->email;
     if ($form->values->layer == 'admin') {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-admin")->fetch();
     } else {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-member")->fetch();
     }
     if (!\Nette\Utils\Validators::isEmail($email)) {
         $this->presenter->flashMessage("Adresa je neplatná");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $passwordGenerate = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
     if ($this->database->table('users')->where(array('email' => $email))->count() == 0) {
         $this->flashMessage("E-mail nenalezen");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $member = new \App\Model\MemberModel($this->database);
     $member->setActivation($email, $passwordGenerate);
     $latte = new \Latte\Engine();
     $latte->setLoader(new \Latte\Loaders\StringLoader());
     $params = array('code' => $passwordGenerate, 'email' => $email, 'settings' => $this->presenter->template->settings);
     $mail = new \Nette\Mail\Message();
     $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($email)->setSubject("Informace o novém hesle")->setHTMLBody($latte->renderToString($lostPass->body, $params));
     $mailer = new \Nette\Mail\SendmailMailer();
     $mailer->send($mail);
     $this->presenter->flashMessage('Informace o zapomenutém hesle odeslány', 'success');
     $this->presenter->redirect(this);
 }
开发者ID:caloriscz,项目名称:caloriscms,代码行数:29,代码来源:LostPassControl.php

示例5: authenticate

 /**
  * @param array $credentials
  * @return Identity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $email = $credentials[0]['email'];
     $user = $this->users->getUser($email);
     if ($user === NULL && $this->autoRegister === FALSE || $user instanceof UserEntity && $user->getActive() == 0) {
         throw new AuthenticationException("User '{$email}' not found.", self::IDENTITY_NOT_FOUND);
     } else {
         if ($user === NULL && $this->autoRegister === TRUE) {
             $result = $this->users->register(array("login" => $email, "password" => Random::generate(), "name" => $credentials[0]['firstName'] . " " . $credentials[0]['lastName'], "firstname" => $credentials[0]['firstName'], "lastname" => $credentials[0]['lastName'], "lastLogged" => new DateTime(), "ip" => $_SERVER['REMOTE_ADDR']));
             if ($result instanceof ContactEntity) {
                 return new Identity($result->getUserID(), $result->getUser()->getRole()->getName(), $result->getUser()->toArray());
             } else {
                 throw new AuthenticationException("User '{$email}' cannot be registered.", self::IDENTITY_NOT_FOUND);
             }
         } else {
             if ($user instanceof UserEntity) {
                 $user->setLastLogged(new DateTime());
                 $user->setIp($_SERVER['REMOTE_ADDR']);
                 $this->users->updateUser($user);
                 $data = $user->toArray();
                 unset($data['password']);
                 return new Identity($user->getUserID(), $user->getRole()->getName(), $data);
             } else {
                 throw new AuthenticationException("User '{$email}' cannot be connected.", self::IDENTITY_NOT_FOUND);
             }
         }
     }
 }
开发者ID:vipercz,项目名称:sandbox,代码行数:33,代码来源:FacebookAuthenticator.php

示例6: generateHash

 protected function generateHash()
 {
     do {
         $hash = Nette\Utils\Random::generate(32);
     } while ($this->getTable()->where([$this->tables['identityHash']['hash'] => $hash])->fetch());
     return $hash;
 }
开发者ID:trejjam,项目名称:authorization,代码行数:7,代码来源:IdentityHash.php

示例7: generate

 public function generate($length = self::DEFAULT_LENGTH, $charlist = self::DEFAULT_CHARLIST)
 {
     Validators::assert($length, 'integer', 'length');
     if ($length < 1) {
         throw new InvalidArgumentException("Length must be greater or equal 1, value '{$length}' given.");
     }
     return Random::generate($length, $charlist);
 }
开发者ID:rebendajirijr,项目名称:passwords,代码行数:8,代码来源:NettePasswordManager.php

示例8: save

 /**
  * Save past text into database
  * Return generated hash
  * @param array $data
  * @return string
  */
 public function save($data)
 {
     $data->hash = Random::generate(6, '0-9a-zA-Z');
     $data->inserted = $this->dateTime->getTimestamp();
     $data->id_user = '';
     $this->dtb->table('pastes')->insert($data);
     return $data->hash;
 }
开发者ID:hadikcz,项目名称:PasteIt,代码行数:14,代码来源:PasteManager.php

示例9: nodeOpened

	/**
	 * New node is found.
	 * @return bool
	 */
	public function nodeOpened(Latte\MacroNode $node)
	{
		$this->used = TRUE;
		$node->isEmpty = FALSE;
		$node->openingCode = Latte\PhpWriter::using($node)
			->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
				Nette\Utils\Random::generate()
			);
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:13,代码来源:CacheMacro.php

示例10: macroVersion

 /**
  * generates random number for front assets versing
  */
 public function macroVersion(MacroNode $node, PhpWriter $writer)
 {
     $length = 10;
     $word = $node->tokenizer->fetchWord();
     if (is_numeric($word)) {
         $length = (int) $word;
     }
     return $writer->write(' ?>?' . Random::generate($length) . '<?php ');
 }
开发者ID:janlanger,项目名称:nette-skeleton,代码行数:12,代码来源:UIMacros.php

示例11: nodeOpened

 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     $this->used = TRUE;
     $node->empty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
开发者ID:nette,项目名称:caching,代码行数:13,代码来源:CacheMacro.php

示例12: nodeOpened

 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
     }
     $this->used = TRUE;
     $node->isEmpty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
开发者ID:4iz278,项目名称:cviceni,代码行数:13,代码来源:CacheMacro.php

示例13: createWorker

 /**
  * @return \Venne\Queue\Worker
  */
 public function createWorker()
 {
     $id = Random::generate(20);
     $this->configManager->lock();
     $data = $this->configManager->loadConfigFile();
     $data['worker'][$id] = array('id' => $id, 'state' => self::STATE_PAUSED, 'lastCheck' => null, 'lastJob' => null);
     $this->configManager->saveConfigFile($data);
     $this->configManager->unlock();
     return $this->getWokrer($id);
 }
开发者ID:venne,项目名称:venne,代码行数:13,代码来源:WorkerManager.php

示例14: computeUnsafeHash

 /**
  * @return string Password grade hash (do not store!)
  */
 protected function computeUnsafeHash()
 {
     if ($this->getValue('hash', FALSE)) {
         throw new InvalidStateException('Hash already set');
     }
     if (!$this->user) {
         throw new InvalidArgumentException();
     }
     return md5($this->createdAt->format('u') . $this->user->email) . Random::generate(15);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:13,代码来源:Token.php

示例15: actionIn

 /**
  * @param $key
  * @throws BadRequestException
  */
 public function actionIn($key)
 {
     $response = $this->api->call('scud', "SCUD_CheckAccess/{$key}");
     if ($response['status'] === "OK") {
         $identity = new Identity(Random::generate(32));
         $this->getUser()->login($identity);
         $this->redirect("Dashboard:default");
     }
     throw new BadRequestException();
 }
开发者ID:pogodi,项目名称:Brain,代码行数:14,代码来源:ScudPresenter.php


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