本文整理汇总了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));
}
示例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));
}