예제 #1
0
 /**
  * request
  *
  * @return  bool
  *
  * @throws \Exception
  */
 protected function request()
 {
     $email = $this->input->getEmail('email');
     if (!$email) {
         $this->setRedirect($this->router->http('forgot'), Translator::translate('windwalker.user.no.email'));
         return false;
     }
     $view = $this->getView();
     $token = md5($this->app->get('secret') . uniqid() . CryptHelper::genRandomBytes());
     $link = $this->router->http('forgot', array('task' => 'confirm', 'token' => $token), Router::TYPE_FULL);
     $user = User::get(array('email' => $email));
     if ($user->notNull()) {
         $password = new Password();
         $user->reset_token = $password->create($token);
         $user->reset_last = DateTime::create('now', DateTime::TZ_LOCALE)->toSql(true);
         User::save($user);
     }
     $view['user'] = $user;
     $view['token'] = $token;
     $view['link'] = $link;
     $body = $view->setLayout('email')->render();
     // Please send email here.
     // ----------------------------------------------------
     // ----------------------------------------------------
     $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), array('This is test message.', $body));
     return true;
 }
예제 #2
0
 /**
  * Method to test decrypt().
  *
  * @return void
  *
  * @covers Windwalker\Crypt\Cipher\McryptCipher::decrypt
  */
 public function testDecrypt()
 {
     // Use IV
     $iv = CryptHelper::genRandomBytes(16);
     $data = $this->instance->encrypt('windwalker', $this->key, $iv);
     $ivSize = strlen($iv);
     $iv = substr($data, 0, $ivSize);
     $data = substr($data, $ivSize);
     $data = $this->instance->decrypt($data, $this->key, $iv);
     $this->assertEquals('windwalker', $data);
 }
예제 #3
0
 /**
  * Method to encrypt a data string.
  *
  * @param   string  $data  The data string to encrypt.
  * @param   string  $key   The private key.
  * @param   string  $iv    The public key.
  *
  * @return  string  The encrypted data string.
  *
  * @since   2.0
  * @throws  \InvalidArgumentException
  */
 public function encrypt($data, $key = null, $iv = null)
 {
     $iv = $iv ?: $this->getIVKey();
     $key = CryptHelper::repeatToLength($key, 24, true);
     // Encrypt the data.
     $encrypted = mcrypt_encrypt($this->type, $key, $data, $this->mode, $iv);
     return $iv . $encrypted;
 }
예제 #4
0
 /**
  * getToken
  *
  * @param string $data
  * @param string $secret
  *
  * @return  string
  */
 public static function getToken($data = null, $secret = null)
 {
     $secret = $secret ?: Ioc::getConfig()->get('system.secret');
     $data = json_encode($data);
     return md5($secret . $data . uniqid() . CryptHelper::genRandomBytes());
 }