当前位置: 首页>>代码示例>>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;未经允许,请勿转载。