當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SecurityUtil::getSaltedHash方法代碼示例

本文整理匯總了PHP中SecurityUtil::getSaltedHash方法的典型用法代碼示例。如果您正苦於以下問題:PHP SecurityUtil::getSaltedHash方法的具體用法?PHP SecurityUtil::getSaltedHash怎麽用?PHP SecurityUtil::getSaltedHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SecurityUtil的用法示例。


在下文中一共展示了SecurityUtil::getSaltedHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getHashedPassword

 /**
  * Given a string return it's hash and the internal integer hashing algorithm code used to hash that string.
  *
  * Note that this can be used for more than just user login passwords. If a user-readale password-like code is needed,
  * then this method may be suitable.
  *
  * @param string $unhashedPassword An unhashed password, as might be entered by a user or generated by the system, that meets
  *                                  all of the constraints of a valid password for a user account.
  * @param int $hashMethodCode An internal code identifying one of the valid user password hashing methods; optional, leave this
  *                                  unset (null) when creating a new password for a user to get the currently configured system
  *                                  hashing method, otherwise to hash a password for comparison, specify the method used to hash
  *                                  the original password.
  *
  * @return array|bool An array containing two elements: 'hash' containing the hashed password, and 'hashMethodCode' containing the
  *                      internal integer hashing algorithm code used to hash the password; false if the password does not meet the
  *                      constraints of a valid password, or if the hashing method (stored in the Users module 'hash_method' var) is
  *                      not valid.
  */
 public static function getHashedPassword($unhashedPassword, $hashMethodCode = null)
 {
     if (isset($hashMethodCode)) {
         if (!is_numeric($hashMethodCode) || (int) $hashMethodCode != $hashMethodCode) {
             return LogUtil::registerArgsError();
         }
         $hashAlgorithmName = self::getPasswordHashMethodName($hashMethodCode);
         if (!$hashAlgorithmName) {
             return LogUtil::registerArgsError();
         }
     } else {
         $hashAlgorithmName = ModUtil::getVar('Users', 'hash_method', '');
         $hashMethodCode = self::getPasswordHashMethodCode($hashAlgorithmName);
         if (!$hashMethodCode) {
             return LogUtil::registerArgsError();
         }
     }
     return SecurityUtil::getSaltedHash($unhashedPassword, $hashAlgorithmName, self::getPasswordHashMethods(false), 5, UsersConstant::SALT_DELIM);
     // FIXME this return is not reached
     return array('hashMethodCode' => $hashMethodCode, 'hash' => hash($hashAlgorithmName, $unhashedPassword));
 }
開發者ID:rtznprmpftl,項目名稱:Zikulacore,代碼行數:39,代碼來源:UserUtil.php

示例2: getHashedPassword

 /**
  * Given a string return it's hash and the internal integer hashing algorithm code used to hash that string.
  *
  * Note that this can be used for more than just user login passwords. If a user-readale password-like code is needed,
  * then this method may be suitable.
  *
  * @param string $unhashedPassword An unhashed password, as might be entered by a user or generated by the system, that meets
  *                                  all of the constraints of a valid password for a user account.
  * @param int $hashMethodCode An internal code identifying one of the valid user password hashing methods; optional, leave this
  *                                  unset (null) when creating a new password for a user to get the currently configured system
  *                                  hashing method, otherwise to hash a password for comparison, specify the method used to hash
  *                                  the original password.
  *
  * @return array|bool An array containing two elements: 'hash' containing the hashed password, and 'hashMethodCode' containing the
  *                      internal integer hashing algorithm code used to hash the password; false if the password does not meet the
  *                      constraints of a valid password, or if the hashing method (stored in the Users module 'hash_method' var) is
  *                      not valid.
  */
 public static function getHashedPassword($unhashedPassword, $hashMethodCode = null)
 {
     if (isset($hashMethodCode)) {
         if (!is_numeric($hashMethodCode) || (int) $hashMethodCode != $hashMethodCode) {
             throw new \InvalidArgumentException(__('Invalid arguments array received'));
         }
         $hashAlgorithmName = self::getPasswordHashMethodName($hashMethodCode);
         if (!$hashAlgorithmName) {
             throw new \InvalidArgumentException(__('Invalid arguments array received'));
         }
     } else {
         $hashAlgorithmName = ModUtil::getVar('ZikulaUsersModule', 'hash_method', '');
         $hashMethodCode = self::getPasswordHashMethodCode($hashAlgorithmName);
         if (!$hashMethodCode) {
             throw new \InvalidArgumentException(__('Invalid arguments array received'));
         }
     }
     return SecurityUtil::getSaltedHash($unhashedPassword, $hashAlgorithmName, self::getPasswordHashMethods(false), 5, UsersConstant::SALT_DELIM);
     // FIXME this return is not reached
     return array('hashMethodCode' => $hashMethodCode, 'hash' => hash($hashAlgorithmName, $unhashedPassword));
 }
開發者ID:rmaiwald,項目名稱:core,代碼行數:39,代碼來源:UserUtil.php


注:本文中的SecurityUtil::getSaltedHash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。