コード例 #1
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $blockCipher = BlockCipher::factory($config['cipher']['adapter'], $config['cipher']['options']);
     $blockCipher->setKey($config['cipher']['encryption_key']);
     return $blockCipher;
 }
コード例 #2
0
 public function zendTest()
 {
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey('encryption key');
     $result = $blockCipher->encrypt('This is secret message');
     return 'Encrypted test: ' . $result;
 }
コード例 #3
0
 public function decrypt($msg, $key, $algo)
 {
     $blockCipher = BlockCipher::factory('mcrypt', $algo);
     $blockCipher->setKey($key);
     $result = $blockCipher->decrypt($msg);
     return $result;
 }
コード例 #4
0
 public function cleanerAction()
 {
     $form = new CleanerForm();
     $form->setAttribute('method', 'POST');
     $repo = array();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost();
         #test cipher
         $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes', 'hash' => 'sha512'));
         $blockCipher->setKey('DA$#3434fsa432dfef32327');
         $hash = 'f19f8bf56c4f61b6b2ca51e4cd5973faa5a165e4db6ad7aae0f065463ba2330fx2kZPSH5xCnLy48nVPWnprIh601be0H2Quh2o88oCws=';
         #\Zend\Debug\Debug::dump($blockCipher->decrypt($hash));
         #test bcrypt
         $bcrypt = new Bcrypt();
         $hash = $bcrypt->create('xxx');
         $hash = '$2y$10$HQORKaG/QUWk.wJGj9lPuOHLTrm11pRdSSBDP.L2JVrAkCid7W5O.';
         #get git data
         $pwd = $request->getPost()['pwd'];
         $hour = $request->getPost()['hour'];
         if ($bcrypt->verify($pwd, $hash) && is_numeric($hour)) {
             $this->getActionLogTable()->deleteOlderThan($hour);
             $result['message'] = 'OK';
         } else {
             $result['message'] = 'Error. Passwd or Hour are not valid.';
         }
     }
     $result['form'] = $form;
     return new ViewModel($result);
 }
コード例 #5
0
ファイル: lltCrypt.php プロジェクト: blackjackedu/FreeMLib
 public static function decrypt($str)
 {
     $bCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $bCipher->setKey('encryption key');
     $rs = $bCipher->decrypt($str);
     return $rs;
 }
コード例 #6
0
 public static function decryptBlockCipher($value_encoded, $encryption_key = '')
 {
     $MY =& MY_Controller::get_instance();
     $MY->load->library('library_zend2');
     $cipher = \Zend\Crypt\BlockCipher::factory('mcrypt', array('algorithm' => 'aes'));
     $cipher->setKey(empty($encryption_key) ? self::$Encryption_Key : $encryption_key);
     return $cipher->decrypt($value_encoded);
 }
コード例 #7
0
 /**
  * @return BlockCipher
  */
 private function getBlockCipher()
 {
     if ($this->block_cipher) {
         return $this->block_cipher;
     }
     $this->block_cipher = BlockCipher::factory('mcrypt', ['padding' => Mcrypt::DEFAULT_PADDING]);
     $this->block_cipher->setKey($this->crypto_key);
     return $this->block_cipher;
 }
コード例 #8
0
 /**
  * 
  * @param string $value
  * @param AbstractPlatform $platform
  * @return string
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     try {
         $v = parent::convertToPHPValue($value, $platform);
         return BlockCipher::factory('mcrypt', array('algo' => 'aes'))->setKey(self::KEY)->decrypt($v);
     } catch (\Exception $ex) {
         return $value;
     }
 }
コード例 #9
0
 /**
  * @see CryptofierCryptoInterface
  *
  * NB: Shouldn't be called externally/by derived classes as doesn't use the server key!
  *
  * @param $value
  * @param $friendlyKey
  *
  * @return string - maybe unfriendly
  * @throws CryptofierException
  */
 protected final function decrypt_native($value, $friendlyKey)
 {
     try {
         $cipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
         $cipher->setKey($this->unfriendly($friendlyKey));
         return $cipher->decrypt($value);
     } catch (Exception $e) {
         throw new CryptofierException("Failed to " . __METHOD__);
     }
 }
コード例 #10
0
 public function decryptPasswords(Account $account)
 {
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey($this->getEncryptionKey());
     if ($account->getSmtpPassword()) {
         $account->setSmtpPassword($blockCipher->decrypt($account->getSmtpPassword()));
     }
     if ($account->getImapPassword()) {
         $account->setImapPassword($blockCipher->decrypt($account->getImapPassword()));
     }
     return $account;
 }
コード例 #11
0
ファイル: ExTable.php プロジェクト: gstearmit/EshopVegeTable
 public function getserver($id)
 {
     $rowset = $this->tableGateway->select(array('id' => $id));
     $row = $rowset->current();
     if (!$row) {
         return false;
     } else {
         $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
         $blockCipher->setKey('foxvsky');
         $row->passwd = $blockCipher->decrypt($row->passwd);
         return $row;
     }
 }
コード例 #12
0
ファイル: AuthApi.php プロジェクト: logue/pukiwiki_adv
 /**
  * コンストラクタ
  */
 public function __construct()
 {
     global $adminpass, $vars;
     //	if (!isset($this->auth_name)) throw new Exception('$this->auth_name has not set.');
     // コールバック先のページ
     $page = isset($vars['page']) ? $vars['page'] : null;
     // 管理人のパスワードのハッシュを暗号/復号のキーとする
     list(, $salt) = Auth::passwd_parse($adminpass);
     // 暗号化/復号化用
     $this->bc = BlockCipher::factory('mcrypt', array('algo' => 'des', 'mode' => 'cfb', 'hash' => 'sha512', 'salt' => $salt));
     // コールバック先のURL。通常プラグインのコールバックアドレスが返される
     $this->callbackUrl = isset($this->auth_name) ? Router::get_resolve_uri($this->auth_name, $vars['page'], 'full') : null;
     // セッション名
     $this->session_name = self::SESSION_PREFIX . md5(Router::get_script_absuri() . session_id());
 }
コード例 #13
0
 public function saveserver(Local $local)
 {
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey('foxvsky');
     $result = $blockCipher->encrypt($local->ftppass);
     //echo "Encrypted text: $result \n";
     //echo $blockCipher->decrypt($result);
     $data = array('svname' => $local->svname, 'ip' => $local->ip, 'ftpusername' => $local->ftpusername, 'ftppass' => $result, 'path' => $local->path, 'link' => $local->link, 'datecreat' => date('Y-m-d H:i:s'));
     $id = (int) $local->id;
     if ($id == 0) {
         $this->tableGateway->insert($data);
         return 0;
     } else {
         return 1;
     }
 }
コード例 #14
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (empty($config['doctrine']['encryption']['key'])) {
         throw new \InvalidArgumentException('You need to define a non-empty key in doctrine.encryption.key config');
     }
     $key = $config['doctrine']['encryption']['key'];
     $salt = null;
     if (!empty($config['doctrine']['encryption']['salt'])) {
         $salt = $config['doctrine']['encryption']['salt'];
     }
     $cipher = \Zend\Crypt\BlockCipher::factory('mcrypt');
     $cipher->setKey($key);
     if ($salt) {
         $cipher->setSalt($salt);
     }
     return $cipher;
 }
コード例 #15
0
ファイル: BlockCipher.php プロジェクト: axelmdev/ecommerce
 /**
  * Class constructor
  *
  * @param  string|array|Traversable $options Encryption Options
  * @throws Exception\RuntimeException
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($options)
 {
     try {
         $this->blockCipher = CryptBlockCipher::factory('mcrypt', $this->encryption);
     } catch (SymmetricException\RuntimeException $e) {
         throw new Exception\RuntimeException('The BlockCipher cannot be used without the Mcrypt extension');
     }
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     } elseif (is_string($options)) {
         $options = ['key' => $options];
     } elseif (!is_array($options)) {
         throw new Exception\InvalidArgumentException('Invalid options argument provided to filter');
     }
     if (array_key_exists('compression', $options)) {
         $this->setCompression($options['compression']);
         unset($options['compress']);
     }
     $this->setEncryption($options);
 }
コード例 #16
0
 /**
  * @return \Zend\Crypt\BlockCipher
  */
 private function _getBlockCipher()
 {
     if (!$this->blockCipher) {
         $blockCipher = \Zend\Crypt\BlockCipher::factory('mcrypt');
         $blockCipher->setKey($this->cryptKey);
         $this->blockCipher = $blockCipher;
     }
     return $this->blockCipher;
 }
コード例 #17
0
ファイル: BlockCipherTest.php プロジェクト: necrogami/zf2
 public function testFactoryEmptyOptions()
 {
     $this->blockCipher = BlockCipher::factory('mcrypt');
     $this->assertTrue($this->blockCipher->getCipher() instanceof Mcrypt);
 }
コード例 #18
0
 public function remoteuploadAction()
 {
     // header------------------------------------------------
     $this->layout('layout/bags');
     $catalog = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getdata'));
     $this->layout()->catalog = $catalog;
     $getuser = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'getuser'));
     // var_dump($getuser);
     $this->layout()->getuser = $getuser;
     // var_dump($getuser);
     $checklogin = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'session'));
     if ($checklogin) {
         if ($getuser->group == 'admin' || $getuser->group == 'supperadmin') {
             $arr = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getdata'));
             // var_dump($arr);
             $form = new RemoteForm('remoteform');
             $form->addElements($arr);
             $tempFile = null;
             // -------------------------------upload mediafire server
             $getuser = $this->checkuserfolder($getuser);
             // -----------------------end mediafire upload-------------------
             $prg = $this->fileprg($form);
             if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
                 return $prg;
                 // Return PRG redirect response
             } elseif (is_array($prg)) {
                 if ($form->isValid()) {
                     $data = $form->getData();
                     $file_remote = $data['urlremote'];
                     $file_headers = @get_headers($file_remote);
                     if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                         $view = new ViewModel();
                         $exists = false;
                         $view->exists = $exists;
                         $view->setVariable('remoteform', $form);
                         return $view;
                     } else {
                         $exists = true;
                         $title = sprintf("%.0f ", microtime(true) * 20000);
                         $title = str_replace(' ', '', $title);
                         $name = md5(date('ymd'));
                         if (!file_exists('temp/data/tmpuploads/videos/' . $name)) {
                             mkdir('temp/data/tmpuploads/videos/' . $name, 0777, true);
                         }
                         $path2 = '/temp/data/tmpuploads/videos/' . $name;
                         $path = ROOT_PATH . $path2;
                         /*
                          * $handle=file_get_contents($file); $fp = fopen($path.'/'.$title.'.mp4', "w"); fclose($fp); file_put_contents($path.'/'.$title.'.mp4', $handle);
                          */
                         $fp = fopen($path . '/' . $title . '.mp4', "w");
                         $ch = curl_init();
                         $agent = $_SERVER['HTTP_USER_AGENT'];
                         // echo $agent;
                         curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
                         curl_setopt($ch, CURLOPT_USERAGENT, $agent);
                         curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
                         curl_setopt($ch, CURLOPT_HEADER, 0);
                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                         curl_setopt($ch, CURLOPT_URL, $file_remote);
                         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                         curl_setopt($ch, CURLOPT_FILE, $fp);
                         // curl_setopt($ch, CURLOPT_HEADER, 0);
                         $k = curl_exec($ch);
                         curl_close($ch);
                         fclose($fp);
                         var_dump($k);
                         // die('stop');
                         // rename(ROOT_PATH.$path,ROOT_PATH.$path2.'/'.$title.'.'.$extension);
                         $convert_link = ROOT_PATH . $path2 . '/' . $title . '.mp4';
                         // --------------------------- UPLOAD TO FTP SERVER-------------------------------------------------------------------------------------------------------------
                         $convert_img = ROOT_PATH . $path2 . '/' . $title . '.jpg';
                         $convert_img_thumbnail = ROOT_PATH . $path2 . '/' . $title . '_thumbnail.jpg';
                         $convert_img_medium = ROOT_PATH . $path2 . '/' . $title . '_medium.jpg';
                         $medium = '500x280';
                         $thumbnail = '250x140';
                         ob_start();
                         passthru("ffmpeg -i {$convert_link} 2>&1");
                         $duration = ob_get_contents();
                         ob_end_clean();
                         $search = '/Duration: (.*?),/';
                         $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
                         $list_time = explode(':', $matches[1][0]);
                         // var_dump($list_time);
                         $video_time = 0;
                         $sizearr = sizeof($list_time);
                         for ($i = 0; $i < $sizearr; $i++) {
                             echo (int) $list_time[$i];
                             echo "</br>";
                             echo pow(60, $sizearr - $i - 1);
                             echo "</br>";
                             $video_time += (int) $list_time[$i] * pow(60, $sizearr - $i - 1);
                         }
                         // echo $video_time;
                         $rand_time = rand(0, $video_time);
                         // echo $rand_time;
                         exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y  {$convert_img} 2>&1 ");
                         exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y -s {$thumbnail} {$convert_img_thumbnail} 2>&1 ");
                         exec("ffmpeg -i {$convert_link} -deinterlace -an -ss {$rand_time} -f mjpeg -t 0.01 -r 1 -y -s {$medium} {$convert_img_medium} 2>&1 ");
                         $path3 = substr($path2, 29);
                         $local = $this->getLocalTable()->getserver(1);
                         $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
                         $blockCipher->setKey('foxvsky');
                         $local->ftppass = $blockCipher->decrypt($local->ftppass);
                         $dir = $local->path . '/data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky');
                         $file = ROOT_PATH . $path2 . '/' . $title . '.mp4';
                         $remote_file = $dir . '/' . md5($title . 'aihoa') . '.mp4';
                         $remote_img = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/large.jpg';
                         $remote_thumbnail = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/thumbnail.jpg';
                         $remote_medium = $local->path . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/medium.jpg';
                         $conn_id = ftp_connect($local->ip);
                         $login_result = ftp_login($conn_id, $local->ftpusername, $local->ftppass);
                         $this->ftp_mksubdirs($conn_id, $local->path, 'data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky'));
                         $this->ftp_mksubdirs($conn_id, $local->path, 'data/upload/images/' . $path3 . '/' . md5($title . 'mylove'));
                         $upload_vid = ftp_put($conn_id, $remote_file, $file, FTP_BINARY);
                         $upload_img = ftp_put($conn_id, $remote_img, $convert_img, FTP_BINARY);
                         $upload_img_thumbnail = ftp_put($conn_id, $remote_thumbnail, $convert_img_thumbnail, FTP_BINARY);
                         $upload_img_medium = ftp_put($conn_id, $remote_medium, $convert_img_medium, FTP_BINARY);
                         $video_link = $local->link . '/data/upload/videos/' . $path3 . '/' . md5($title . 'foxvsky') . '/' . md5($title . 'aihoa') . '.mp4';
                         $img_link = $local->link . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove') . '/large.jpg';
                         echo "<img src='http://" . $img_link . "'/></br>";
                         echo "<video src='http://" . $video_link . "'/></video></br>";
                         ftp_close($conn_id);
                         // ------------------------------------------------END FTP UPLOAD--------------------------------------------------------------------------------------------------------------------
                         // ------------------------------------------------UPLOAD MEDIAFIRE SERVER-------------------------------------------------------------------------------------------------------------
                         $getuser = $this->checkuserfolder($getuser);
                         $hash = hash_file('sha256', $convert_link);
                         $size = filesize($convert_link);
                         $files = array();
                         $files['filename'] = $title . '.mp4';
                         $files['hash'] = $hash;
                         $files['size'] = $size;
                         $files['url'] = 'http://' . $video_link;
                         $files['folder_key'] = $getuser->folder_key;
                         // var_dump($file);
                         // echo "</br>";
                         $ex = $this->getExTable()->getserver($getuser->externalsv_id);
                         $mediafire = new ConnectMS($ex);
                         $add = $mediafire->add_web_upload($files);
                         $quickkey = $mediafire->instant($files);
                         if (!isset($quickkey) && !$quickey) {
                             $quickkey = '';
                             $direct_link = '';
                         } else {
                             $direct_link = $mediafire->get_link($quickkey);
                         }
                         $video = new Main();
                         $video->exchangeArray($form->getData());
                         $video->seriecode = $title;
                         $video->duration = substr($matches[1][0], 0, 8);
                         $video->folder_key = $getuser->folder_key;
                         $video->quick_key = $quickkey;
                         $video->local_link = 'http://' . $video_link;
                         $video->imgfolder = 'http://' . $local->link . '/data/upload/images/' . $path3 . '/' . md5($title . 'mylove');
                         $video->localsv_id = $local->id;
                         $video->externalsv_id = $getuser->externalsv_id;
                         $video->external_link = $direct_link;
                         // var_dump($video);die('123');
                         // ------------------------------------------------END MEDIAFIRE UPLOAD------------------------------------------------------------------------------------
                         $check = $this->getMainTable()->saveVideo($video);
                         if (!$check) {
                             return $this->redirect()->toUrl(WEBPATH . '/main/edit/' . $title, true);
                         } else {
                             $this->layout()->check = $check;
                         }
                     }
                 } else {
                     $fileErrors = $form->get('seriecode')->getMessages();
                     if (empty($fileErrors)) {
                         $tempFile = $form->get('seriecode')->getValue();
                     }
                 }
             }
             return array('remoteform' => $form, 'tempFile' => $tempFile);
         } else {
             return $this->layout('error/admin');
         }
     } else {
         return $this->layout('error/admin');
     }
 }
コード例 #19
0
ファイル: Bootstrap.php プロジェクト: vfeelit/YZend
 public function _init(Dispatcher $dispatcher)
 {
     // 引入Composer,Yaf扩展的配置项yaf.use_spl_autoload务必设置为1
     if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
         $loader = (include ROOT_PATH . '/vendor/autoload.php');
         //$loader->add("",ROOT_PATH.'/library');
         //$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend');
         Registry::set('loader', $loader);
     }
     // 禁止自动渲染
     $dispatcher->autoRender(FALSE);
     // 保存配置
     $this->_config = Application::app()->getConfig();
     Registry::set('config', $this->_config);
     // 报错设置
     if ($this->_config->global->showError) {
         error_reporting(-1);
         ini_set('display_errors', 'On');
     }
     // 加解密
     if (!empty($this->_config->global->key)) {
         Registry::set('enc', function () {
             $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
             $blockCipher->setKey($this->_config->global->key);
             return $blockCipher;
         });
     }
     // 命令行方式,跳过SESSION
     if (!defined("RUN_IN_CLI")) {
         // 保存路径
         $sessionConfig = $this->_config->session->toArray();
         if (isset($sessionConfig['save_path'])) {
             @mkdir($sessionConfig['save_path'], 0777, true);
         }
         // 配置
         $config = new SessionConfig();
         $config->setOptions($sessionConfig);
         // 会话管理器
         $manager = new SessionManager($config);
         // 开启会话
         $manager->start();
         // 验证会话
         $manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
         if (!$manager->isValid()) {
             $manager->destroy();
             throw new \Exception("会话验证失败");
         }
         // 会话Token
         $default = new Zend\Session\Container();
         if (empty($default->offsetGet('securityToken'))) {
             $default->offsetSet('securityToken', md5(uniqid(rand(), true)));
         }
         // 保存实例
         Registry::set('session', $default);
         Registry::set('sm', $manager);
     }
     // 数据库
     Registry::set('db', function () {
         $mysqlMasterConfig = $this->_config->mysql->master->toArray();
         $adapter = new Adapter($mysqlMasterConfig);
         $connect = $adapter->getDriver()->getConnection();
         for ($i = 0; $i < 5; $i++) {
             if ($connect->isConnected()) {
                 break;
             }
             $connect->connect();
         }
         return $adapter;
     });
     // 邮件
     Registry::set('mail', function () {
         $options = new SmtpOptions($this->_config->smtp->toArray());
         $mail = new SmtpTransport();
         $mail->setOptions($options);
         return $mail;
     });
     // 日志
     Registry::set('logger', function () {
         $logger = new Zend\Log\Logger();
         $writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log");
         $logger->addWriter($writer);
         return $logger;
     });
 }
コード例 #20
0
ファイル: Identity.php プロジェクト: rjakes/SimpleFM
 /**
  * @param string $password
  */
 public function setPassword($password, $encryptionKey)
 {
     /**
      * Password is encrypted so that the identity object is never at rest
      * (e.g. in the session file or database) with a password in clear text.
      */
     if (!is_string($password)) {
         throw new Exception\InvalidArgumentException('The password must be a string');
     }
     if (empty($encryptionKey)) {
         throw new Exception\InvalidArgumentException('The encryptionKey must not be empty');
     }
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey($encryptionKey);
     $this->password = $blockCipher->encrypt($password);
     $this;
 }
コード例 #21
0
ファイル: CipherWrapper.php プロジェクト: xxdavid/texist
 public function __construct($key)
 {
     $this->cipher = BlockCipher::factory('mcrypt');
     $this->cipher->setKey($key);
 }
コード例 #22
0
ファイル: RegistrationForm.php プロジェクト: Mendim/ep3-bs
 public function init()
 {
     $this->setName('rf');
     /* Credentials */
     $this->add(array('name' => 'rf-email1', 'type' => 'Text', 'attributes' => array('id' => 'rf-email1', 'class' => 'autofocus', 'style' => 'width: 250px;'), 'options' => array('label' => 'Email address', 'label_attributes' => array('class' => 'symbolic symbolic-email'), 'notes' => 'Please provide your email address')));
     $this->add(array('name' => 'rf-email2', 'type' => 'Text', 'attributes' => array('id' => 'rf-email2', 'style' => 'width: 250px;'), 'options' => array('label' => ' ', 'notes' => 'Please type your email address again<br>to prevent typing errors')));
     $this->add(array('name' => 'rf-pw1', 'type' => 'Password', 'attributes' => array('id' => 'rf-pw1', 'style' => 'width: 250px;'), 'options' => array('label' => 'Password', 'label_attributes' => array('class' => 'symbolic symbolic-pw'), 'notes' => 'Your password will be safely encrypted')));
     $this->add(array('name' => 'rf-pw2', 'type' => 'Password', 'attributes' => array('id' => 'rf-pw2', 'style' => 'width: 250px;'), 'options' => array('label' => ' ', 'notes' => 'Please type your password again<br>to prevent typing errors')));
     /* Personal data */
     $this->add(array('name' => 'rf-gender', 'type' => 'Select', 'attributes' => array('id' => 'rf-gender'), 'options' => array('label' => 'Salutation', 'value_options' => User::$genderOptions)));
     $this->add(array('name' => 'rf-firstname', 'type' => 'Text', 'attributes' => array('id' => 'rf-firstname', 'style' => 'width: 116px;'), 'options' => array('label' => 'First & Last name')));
     $this->add(array('name' => 'rf-lastname', 'type' => 'Text', 'attributes' => array('id' => 'rf-lastname', 'style' => 'width: 116px;'), 'options' => array('label' => 'Last name')));
     $this->add(array('name' => 'rf-street', 'type' => 'Text', 'attributes' => array('id' => 'rf-street', 'style' => 'width: 182px;'), 'options' => array('label' => 'Street & Number')));
     $this->add(array('name' => 'rf-number', 'type' => 'Text', 'attributes' => array('id' => 'rf-number', 'style' => 'width: 50px;'), 'options' => array('label' => 'Street number')));
     $this->add(array('name' => 'rf-zip', 'type' => 'Text', 'attributes' => array('id' => 'rf-zip', 'style' => 'width: 116px;'), 'options' => array('label' => 'Postal code & City')));
     $this->add(array('name' => 'rf-city', 'type' => 'Text', 'attributes' => array('id' => 'rf-city', 'style' => 'width: 116px;'), 'options' => array('label' => 'City')));
     $this->add(array('name' => 'rf-phone', 'type' => 'Text', 'attributes' => array('id' => 'rf-phone', 'style' => 'width: 250px;'), 'options' => array('label' => 'Phone number', 'notes' => 'We only use this to inform you<br>about changes to your bookings')));
     $this->add(array('name' => 'rf-birthdate', 'type' => 'Text', 'attributes' => array('id' => 'rf-birthdate', 'style' => 'width: 116px;'), 'options' => array('label' => 'Birthday', 'notes' => 'This is optional')));
     /* Add business terms and privacy policy if configured */
     $termsFile = $this->optionManager->get('service.user.registration.terms.file');
     if ($termsFile) {
         $this->add(array('name' => 'rf-terms', 'type' => 'Checkbox', 'attributes' => array('id' => 'rf-terms'), 'options' => array('label' => 'I agree to %s', 'checked_value' => 'true', 'unchecked_value' => 'false')));
     }
     $privacyFile = $this->optionManager->get('service.user.registration.privacy.file');
     if ($privacyFile) {
         $this->add(array('name' => 'rf-privacy', 'type' => 'Checkbox', 'attributes' => array('id' => 'rf-privacy'), 'options' => array('label' => 'I agree to %s', 'checked_value' => 'true', 'unchecked_value' => 'false')));
     }
     /* Add fake nickname to fool spam bots */
     $this->add(array('name' => 'rf-nickname', 'type' => 'Text', 'attributes' => array('style' => 'display: none;')));
     /* Add AES encrypted timestamp for security */
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey('A balrog, a demon of the ancient world. Its foe is beyond any of you, RUN!');
     $this->add(array('name' => 'rf-csrf', 'type' => 'Hidden', 'attributes' => array('value' => $blockCipher->encrypt(time()))));
     $this->add(array('name' => 'rf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Complete registration', 'class' => 'default-button', 'style' => 'width: 250px;')));
     /* Input filters */
     $userManager = $this->userManager;
     $factory = new Factory();
     $this->setInputFilter($factory->createInputFilter(array('rf-email1' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => true, 'message' => 'Please type your correct email address here', 'messages' => array('emailAddressInvalidMxRecord' => 'We could not verify your email provider')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
         $blacklist = getcwd() . '/data/res/blacklist-emails.txt';
         if (is_readable($blacklist)) {
             $blacklistContent = file_get_contents($blacklist);
             $blacklistDomains = explode("\r\n", $blacklistContent);
             foreach ($blacklistDomains as $blacklistDomain) {
                 $blacklistPattern = str_replace('.', '\\.', $blacklistDomain);
                 if (preg_match('/' . $blacklistPattern . '$/', $value)) {
                     return false;
                 }
             }
         }
         return true;
     }, 'message' => 'Trash mail addresses are currently blocked - sorry'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($userManager) {
         if ($userManager->getBy(array('email' => $value))) {
             return false;
         } else {
             return true;
         }
     }, 'message' => 'This email address has already been registered')))), 'rf-email2' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'rf-email1', 'message' => array('Both email addresses must be identical'))))), 'rf-pw1' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 4, 'message' => 'Your password should be at least %min% characters long')))), 'rf-pw2' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'rf-pw1', 'message' => array('Both passwords must be identical'))))), 'rf-firstname' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your name here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Your name is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\&\'\\(\\)\\+\\,\\-\\.0-9\\x{00c0}-\\x{01ff}a-zA-Z])+$/u', 'message' => 'Your name contains invalid characters - sorry')))), 'rf-lastname' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Your last name is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \'\\+\\-\\x{00c0}-\\x{01ff}a-zA-Z])+$/u', 'message' => 'Your last name contains invalid characters - sorry')))), 'rf-street' => array('filters' => array(array('name' => 'StringTrim'), array('name' => 'Callback', 'options' => array('callback' => function ($name) {
         return ucfirst($name);
     }))), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your street name here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'This street name is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\.\'\\-\\x{00c0}-\\x{01ff}a-zA-Z])+$/u', 'message' => 'This street name contains invalid characters - sorry')))), 'rf-number' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your street number here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^([0-9a-zA-Z\\.\\-])+$/u', 'message' => 'This street number contains invalid characters - sorry')))), 'rf-zip' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your postal code here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]{4,6}$/', 'message' => 'Please provide a correct postal code')))), 'rf-city' => array('filters' => array(array('name' => 'StringTrim'), array('name' => 'Callback', 'options' => array('callback' => function ($name) {
         return ucfirst($name);
     }))), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your city here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'This city name is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\&\'\\(\\)\\-\\x{00c0}-\\x{01ff}a-zA-Z])+$/u', 'message' => 'This city name contains invalid characters - sorry')))), 'rf-phone' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your phone number here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'This phone number is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\+\\/\\(\\)\\-0-9])+$/u', 'message' => 'This phone number contains invalid characters - sorry')))), 'rf-birthdate' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))), 'rf-terms' => array('required' => false, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please accept this'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
         return $value === 'true';
     }, 'message' => 'Please agree to this'), 'break_chain_on_failure' => true))), 'rf-privacy' => array('required' => false, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please accept this'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) {
         return $value === 'true';
     }, 'message' => 'Please agree to this'), 'break_chain_on_failure' => true))), 'rf-nickname' => array('required' => false, 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 0, 'message' => 'Please leave this field empty')))), 'rf-csrf' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please register over our website only'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($blockCipher) {
         $time = $blockCipher->decrypt($value);
         if (!is_numeric($time)) {
             return false;
         }
         // Allow form submission after five seconds and until one hour
         if (time() - $time < 5 || time() - $time > 60 * 60) {
             return false;
         } else {
             return true;
         }
     }, 'message' => 'You were too quick for our system! Please wait some seconds and try again. Thank you!')))))));
 }
コード例 #23
0
 /**
  * @param string $encryptionKey
  */
 public function __construct($encryptionKey)
 {
     $this->blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $this->blockCipher->setKey($encryptionKey);
 }
コード例 #24
0
 public static function decrypt($encryptedText, $key)
 {
     $cipher = BlockCipher::factory('mcrypt', array('algorithm' => 'aes'));
     $cipher->setKey($key);
     return $cipher->decrypt($encryptedText);
 }
コード例 #25
0
 /**
  * Constructor
  *
  * @param BlockCipher $blockCipher
  * @param Rsa $public
  */
 public function __construct(BlockCipher $bCipher = null, Rsa $rsa = null)
 {
     $this->bCipher = null === $bCipher ? BlockCipher::factory('openssl') : $bCipher;
     $this->rsa = null === $rsa ? new PublicKey\Rsa() : $rsa;
 }
コード例 #26
0
ファイル: htdigest.inc.php プロジェクト: logue/pukiwiki_adv
function htdigest_save($username, $p_realm, $hash, $role)
{
    global $realm, $_htdigest_msg;
    if ($realm != $p_realm) {
        return $_htdigest_msg['msg_realm'];
    }
    // DES
    if ($role > 2) {
        $key = htdigest_get_hash($username, $p_realm);
    } else {
        // adminpass
        global $adminpass;
        list($scheme, $key) = Auth::passwd_parse($adminpass);
        // FIXME: MD5 ONLY
        if ($scheme != '{x-php-md5}') {
            return $_htdigest_msg['err_md5'];
        }
    }
    $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'des', 'mode' => 'cfb', 'hash' => 'sha512', 'salt' => $key, 'padding' => 2));
    $decrypted_hash = $blockCipher->decrypt($hash);
    //	$hash = des($key, base64_decode($hash), 0, 0, null);
    if (!preg_match('/^[a-z0-9]+$/iD', $decrypted_hash)) {
        return $_htdigest_msg['err_key'];
    }
    // SAVE
    if (file_exists(HTDIGEST_FILE)) {
        $lines = file(HTDIGEST_FILE);
    } else {
        $fp = fopen(HTDIGEST_FILE, 'w');
        @flock($fp, LOCK_EX);
        fputs($fp, $username . ':' . $realm . ':' . $decrypted_hash . "\n");
        @flock($fp, LOCK_UN);
        @fclose($fp);
        return $_htdigest_msg['msg_1st'];
    }
    $sw = FALSE;
    foreach ($lines as &$line) {
        $field = explode(':', trim($line));
        if ($field[0] == $username && $field[1] == $p_realm) {
            if ($field[2] == $decrypted_hash) {
                return $_htdigest_msg['msg_not_update'];
            }
            $sw = TRUE;
            $line = $field[0] . ':' . $field[1] . ':' . $decrypted_hash . "\n";
            break;
        }
    }
    if (!$sw) {
        $fp = fopen(HTDIGEST_FILE, 'a');
        @flock($fp, LOCK_EX);
        fputs($fp, $username . ':' . $p_realm . ':' . $decrypted_hash . "\n");
        @flock($fp, LOCK_UN);
        @fclose($fp);
        return $_htdigest_msg['msg_add'];
    }
    $fp = fopen(HTDIGEST_FILE, 'w');
    @flock($fp, LOCK_EX);
    foreach ($lines as $line) {
        fwrite($fp, $line);
    }
    @flock($fp, LOCK_UN);
    @fclose($fp);
    return $_htdigest_msg['msg_update'];
}
コード例 #27
0
 /**
  *
  * @param field_type $outgoingPassword nocomment
  * @return empty
  */
 public function setOutgoingPassword($outgoingPassword)
 {
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     if ($this->_getSecretKey() != '') {
         $blockCipher->setKey($this->_getSecretKey());
         $outgoingPassword = $blockCipher->encrypt($outgoingPassword);
         $this->outgoingPassword = $outgoingPassword;
     }
 }
コード例 #28
0
 /**
  * @return \Zend\Crypt\BlockCipher
  */
 protected function getBlockCipher()
 {
     $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
     $blockCipher->setKey($this->secret);
     return $blockCipher;
 }