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


PHP JCrypt::encrypt方法代码示例

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


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

示例1: encrypt

 /**
  * Encrypt data.
  *
  * @param array $keys That must be an array that contains private and public keys.
  * @param mixed $data The data that has to be encrypted.
  *
  * @return mixed
  */
 public static function encrypt(array $keys, $data)
 {
     $chiper = new JCryptCipherRijndael256();
     $key = new JCryptKey("rijndael256", $keys["private"], $keys["public"]);
     $crypt = new JCrypt($chiper, $key);
     return $crypt->encrypt($data);
 }
开发者ID:xop32,项目名称:Proof-of-Identity,代码行数:15,代码来源:identityproof.php

示例2: login

 /**
  * Login authentication function.
  *
  * Username and encoded password are passed the onUserLogin event which
  * is responsible for the user validation. A successful validation updates
  * the current session record with the user's details.
  *
  * Username and encoded password are sent as credentials (along with other
  * possibilities) to each observer (authentication plugin) for user
  * validation.  Successful validation will update the current session with
  * the user details.
  *
  * @param   array  $credentials  Array('username' => string, 'password' => string)
  * @param   array  $options      Array('remember' => boolean)
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  */
 public function login($credentials, $options = array())
 {
     // Get the global JAuthentication object.
     jimport('joomla.user.authentication');
     $authenticate = JAuthentication::getInstance();
     $response = $authenticate->authenticate($credentials, $options);
     if ($response->status === JAuthentication::STATUS_SUCCESS) {
         // validate that the user should be able to login (different to being authenticated)
         // this permits authentication plugins blocking the user
         $authorisations = $authenticate->authorise($response, $options);
         foreach ($authorisations as $authorisation) {
             $denied_states = array(JAuthentication::STATUS_EXPIRED, JAuthentication::STATUS_DENIED);
             if (in_array($authorisation->status, $denied_states)) {
                 // Trigger onUserAuthorisationFailure Event.
                 $this->triggerEvent('onUserAuthorisationFailure', array((array) $authorisation));
                 // If silent is set, just return false.
                 if (isset($options['silent']) && $options['silent']) {
                     return false;
                 }
                 // Return the error.
                 switch ($authorisation->status) {
                     case JAuthentication::STATUS_EXPIRED:
                         return JError::raiseWarning('102002', JText::_('JLIB_LOGIN_EXPIRED'));
                         break;
                     case JAuthentication::STATUS_DENIED:
                         return JError::raiseWarning('102003', JText::_('JLIB_LOGIN_DENIED'));
                         break;
                     default:
                         return JError::raiseWarning('102004', JText::_('JLIB_LOGIN_AUTHORISATION'));
                         break;
                 }
             }
         }
         // Import the user plugin group.
         JPluginHelper::importPlugin('user');
         // OK, the credentials are authenticated and user is authorised.  Lets fire the onLogin event.
         $results = $this->triggerEvent('onUserLogin', array((array) $response, $options));
         /*
          * If any of the user plugins did not successfully complete the login routine
          * then the whole method fails.
          *
          * Any errors raised should be done in the plugin as this provides the ability
          * to provide much more information about why the routine may have failed.
          */
         if (!in_array(false, $results, true)) {
             // Set the remember me cookie if enabled.
             if (isset($options['remember']) && $options['remember']) {
                 // Create the encryption key, apply extra hardening using the user agent string.
                 $privateKey = self::getHash(@$_SERVER['HTTP_USER_AGENT']);
                 $key = new JCryptKey('simple', $privateKey, $privateKey);
                 $crypt = new JCrypt(new JCryptCipherSimple(), $key);
                 $rcookie = $crypt->encrypt(json_encode($credentials));
                 $lifetime = time() + 365 * 24 * 60 * 60;
                 // Use domain and path set in config for cookie if it exists.
                 $cookie_domain = $this->getCfg('cookie_domain', '');
                 $cookie_path = $this->getCfg('cookie_path', '/');
                 // Check for SSL connection
                 $secure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || getenv('SSL_PROTOCOL_VERSION');
                 setcookie(self::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, $cookie_path, $cookie_domain, $secure, true);
             }
             return true;
         }
     }
     // Trigger onUserLoginFailure Event.
     $this->triggerEvent('onUserLoginFailure', array((array) $response));
     // If silent is set, just return false.
     if (isset($options['silent']) && $options['silent']) {
         return false;
     }
     // If status is success, any error will have been raised by the user plugin
     if ($response->status !== JAuthentication::STATUS_SUCCESS) {
         JError::raiseWarning('102001', $response->error_message);
     }
     return false;
 }
开发者ID:brojask,项目名称:colegio-abogados-joomla,代码行数:94,代码来源:application.php

示例3: getCURL


//.........这里部分代码省略.........
         foreach ($matches[0] as $index => $match) {
             // Extract the cookie-information
             $cookieName = $matches[1][$index];
             $cookieValue = $matches[2][$index];
             // Strip the meta-data from the cookie
             if (preg_match('/^([^\\;]+)\\;(.*)/', $cookieValue, $cookieValueMatch)) {
                 $cookieValue = $cookieValueMatch[1];
             }
             // Trim the cookie
             $cookieValue = trim($cookieValue);
             // Check if the cookie was dealt with or not
             if (in_array($cookieName, $matchedCookies)) {
                 continue;
             } else {
                 $matchedCookies[] = $cookieName;
             }
             // Set the cookie
             if (!headers_sent()) {
                 if ($cookieName == 'persistent_shopping_cart' && isset($matches[3][$index]) && preg_match('/expires=([^\\;]+)/', $matches[3][$index], $paramsMatch)) {
                     $expires = strtotime($paramsMatch[1]);
                 } else {
                     $expires = 0;
                 }
                 setcookie($cookieName, $cookieValue, $expires, '/', '.' . JURI::getInstance()->toString(array('host')));
                 $_COOKIE[$cookieName] = $cookieValue;
             }
             // Store this cookie also in the default Joomal! session (in case extra cookies are disabled)
             $session = JFactory::getSession();
             $session->set('magebridge.cookie.' . $cookieName, $cookieValue);
         }
     }
     // Handle the extra remember-me cookie
     $user = JFactory::getUser();
     if ($user->id > 0 && !empty($_COOKIE['persistent_shopping_cart'])) {
         $password = $user->password_clear;
         if (empty($password)) {
             $password = $this->input->getString('password');
         }
         if (empty($password)) {
             $password = $user->password;
         }
         if (!empty($password)) {
             $credentials = array('username' => $user->username, 'password' => $password);
             // Create the encryption key, apply extra hardening using the user agent string.
             $privateKey = JApplication::getHash(@$_SERVER['HTTP_USER_AGENT']);
             $key = new JCryptKey('simple', $privateKey, $privateKey);
             $crypt = new JCrypt(new JCryptCipherSimple(), $key);
             $rcookie = $crypt->encrypt(serialize($credentials));
             $lifetime = time() + 365 * 24 * 60 * 60;
             // Use domain and path set in config for cookie if it exists.
             $cookie_domain = JFactory::getConfig()->get('cookie_domain', '');
             $cookie_path = JFactory::getConfig()->get('cookie_path', '/');
             setcookie(JApplication::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, $cookie_path, $cookie_domain);
         }
     }
     // Handle redirects
     preg_match('/^Location: ([^\\s]+)/m', $this->head['headers'], $matches);
     if ($this->allow_redirects && (preg_match('/^3([0-9]+)/', $this->head['http_code']) || !empty($matches))) {
         $originalLocation = trim(array_pop($matches));
         $location = $originalLocation;
         // Check for a location-override
         if ($this->getHeader('X-MageBridge-Location') != null) {
             // But only override the location, if there is no error present
             if (strstr($location, 'startcustomization=1') == false) {
                 $this->debug->notice('X-MageBridge-Location = ' . $this->getHeader('X-MageBridge-Location'));
                 $location = $this->getHeader('X-MageBridge-Location');
             }
         }
         // Check for a location-override if the customer is logged in
         if ($this->getHeader('X-MageBridge-Location-Customer') != null && $this->getHeader('X-MageBridge-Customer') != null) {
             MageBridgeModelUser::getInstance()->postlogin($this->getHeader('X-MageBridge-Customer'), null, true, true);
             $this->debug->notice('X-MageBridge-Location-Customer = ' . $this->getHeader('X-MageBridge-Location-Customer'));
             $location = $this->getHeader('X-MageBridge-Location-Customer');
         }
         // Check for the location in the CURL-information
         if (empty($location) && isset($this->head['info']['redirect_url'])) {
             $location = $this->head['info']['redirect_url'];
         }
         // No location could be found
         if (empty($location)) {
             $this->debug->trace('Redirect requested but no URL found', $this->head['headers']);
             return false;
         }
         // Check if the current location is the Magento homepage, and if so, override it with the Joomla!-stored referer instead
         $referer = $this->bridge->getHttpReferer();
         if ($location == $this->bridge->getJoomlaBridgeUrl()) {
             if (MagebridgeModelConfig::load('use_homepage_for_homepage_redirects') == 1) {
                 $location = JURI::base();
             } elseif (MagebridgeModelConfig::load('use_referer_for_homepage_redirects') == 1 && !empty($referer) && $referer != JURI::current()) {
                 $location = $referer;
             }
         }
         //$location = preg_replace('/magebridge\.php\//', '', $location);
         $this->debug->warning('Trying to redirect to new location ' . $location);
         header('X-MageBridge-Redirect: ' . $originalLocation);
         $this->setRedirect($location);
     }
     curl_close($handle);
     return $this->body;
 }
开发者ID:apiceweb,项目名称:MageBridgeCore,代码行数:101,代码来源:proxy.php

示例4: encrypt

 /**
  * Encrypt a string
  *
  * @param   string  $s  String to encrypt
  *
  * @return  string
  *
  * @since   11.1
  * @deprecated  12.3  Use JCrypt instead.
  */
 public function encrypt($s)
 {
     return $this->_crypt->encrypt($s);
 }
开发者ID:shoffmann52,项目名称:install-from-web-server,代码行数:14,代码来源:simplecrypt.php

示例5: processSubscription

 /**
  * Process Subscription 
  *
  * @param array $data
  */
 function processSubscription($data)
 {
     jimport('joomla.user.helper');
     $db = JFactory::getDbo();
     $row = JTable::getInstance('OsMembership', 'Subscriber');
     $query = $db->getQuery(true);
     $config = OSMembershipHelper::getConfig();
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $nullDate = $db->getNullDate();
     $fieldSuffix = OSMembershipHelper::getFieldSuffix();
     if (!$userId && $config->registration_integration) {
         //Store user account into Joomla users database
         if ($config->create_account_when_membership_active !== '1') {
             $userId = OSMembershipHelper::saveRegistration($data);
         } else {
             //Encrypt the password and store into  #__osmembership_subscribers table and create the account layout
             $privateKey = md5(JFactory::getConfig()->get('secret'));
             $key = new JCryptKey('simple', $privateKey, $privateKey);
             $crypt = new JCrypt(new JCryptCipherSimple(), $key);
             $data['user_password'] = $crypt->encrypt($data['password1']);
         }
     }
     $data['transaction_id'] = strtoupper(JUserHelper::genRandomPassword(16));
     $row->bind($data);
     $row->published = 0;
     $row->created_date = JFactory::getDate()->toSql();
     $row->user_id = $userId;
     while (true) {
         $subscriptionCode = JUserHelper::genRandomPassword(10);
         $query->select('COUNT(*)')->from('#__osmembership_subscribers')->where('subscription_code=' . $db->quote($subscriptionCode));
         $db->setQuery($query);
         $total = $db->loadResult();
         if (!$total) {
             break;
         }
     }
     $row->subscription_code = $subscriptionCode;
     $query->clear();
     $query->select('id')->from('#__osmembership_subscribers')->where("is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')");
     $db->setQuery($query);
     $profileId = $db->loadResult();
     if ($profileId) {
         $row->is_profile = 0;
         $row->profile_id = $profileId;
     } else {
         $row->is_profile = 1;
     }
     $row->language = JFactory::getLanguage()->getTag();
     $query->clear();
     $query->select('*, title' . $fieldSuffix . ' AS title')->from('#__osmembership_plans')->where('id=' . (int) $data['plan_id']);
     $db->setQuery($query);
     $rowPlan = $db->loadObject();
     $rowFields = OSMembershipHelper::getProfileFields($row->plan_id, false);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData(true);
     $fees = OSMembershipHelper::calculateSubscriptionFee($rowPlan, $form, $data, $config, $row->payment_method);
     $action = $data['act'];
     if ($action == 'renew') {
         $renewOptionId = (int) $data['renew_option_id'];
         if ($renewOptionId == OSM_DEFAULT_RENEW_OPTION_ID) {
             $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
         } else {
             $query->clear();
             $query->select('number_days')->from('#__osmembership_renewrates')->where('id=' . (int) $data['renew_option_id']);
             $db->setQuery($query);
             $numberDays = (int) $db->loadResult();
             $dateIntervalSpec = 'P' . $numberDays . 'D';
         }
     } elseif ($action == 'upgrade') {
         $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
     } else {
         if ($rowPlan->recurring_subscription && $rowPlan->trial_duration) {
             $dateIntervalSpec = 'P' . $rowPlan->trial_duration . $rowPlan->trial_duration_unit;
         } else {
             $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit;
         }
     }
     $maxDate = null;
     if ($row->user_id > 0) {
         //Subscriber, user existed
         $query->clear();
         $query->select('MAX(to_date)')->from('#__osmembership_subscribers')->where('user_id=' . $row->user_id . ' AND plan_id=' . $row->plan_id . ' AND (published=1 OR (published = 0 AND payment_method LIKE "os_offline%"))');
         $db->setQuery($query);
         $maxDate = $db->loadResult();
     }
     if ($maxDate) {
         $date = JFactory::getDate($maxDate);
         $row->from_date = $date->add(new DateInterval('P1D'))->toSql();
     } else {
         $date = JFactory::getDate();
         $row->from_date = $date->toSql();
     }
     if ($rowPlan->expired_date && $rowPlan->expired_date != $nullDate) {
         $expiredDate = JFactory::getDate($rowPlan->expired_date);
//.........这里部分代码省略.........
开发者ID:vstorm83,项目名称:propertease,代码行数:101,代码来源:register.php


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