本文整理汇总了PHP中password_get_info函数的典型用法代码示例。如果您正苦于以下问题:PHP password_get_info函数的具体用法?PHP password_get_info怎么用?PHP password_get_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了password_get_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHashInfo
public function getHashInfo($hash)
{
$passwordGetInfoResult = password_get_info($hash);
$identifier = $passwordGetInfoResult[HashInfo::ALGORITHM_ID_KEY];
$name = $passwordGetInfoResult[HashInfo::ALGORITHM_NAME_KEY];
$options = $passwordGetInfoResult[HashInfo::OPTIONS_KEY];
return new HashInfo($identifier, $name, $options);
}
示例2: update
public function update($params)
{
if (isset($params['password'])) {
if (!password_get_info($params['password'])['algo']) {
$params['password'] = password_hash($params['password'], PASSWORD_DEFAULT);
}
}
return parent::update($params);
}
示例3: password_hashing
public function password_hashing()
{
echo '<a href="http://www.codeigniter.com/user_guide/general/compatibility_functions.html">read</a>';
$hash = 'password_hash';
echo password_hash($hash, PASSWORD_DEFAULT);
echo password_get_info($hash);
echo password_needs_rehash($hash, PASSWORD_DEFAULT);
echo password_verify('password_hash', $hash);
}
示例4: __construct
/**
* @param string $password
* @param boolean $automateHash
*/
public function __construct($password, $automateHash = false)
{
$this->password = (string) $password;
$info = password_get_info($this->password);
$this->isHashed = 'unknown' !== $info['algoName'];
if ($automateHash) {
$this->hash();
}
}
示例5: getInfo
/**
* @param string $hash
* @return array
*/
public function getInfo($hash)
{
$clear = Helpers::getHash($hash);
$signatureLength = $this->getSignatureLength();
$ivLength = $this->getIvLength();
if (!$this->verifySignature(Helpers::substr($clear, 0, $signatureLength), Helpers::substr($clear, $signatureLength))) {
throw new \Ark8\Passwords\Exceptions\SignatureException('Signature does not match.');
}
return password_get_info($this->decrypt(Helpers::substr($clear, $signatureLength, $ivLength), Helpers::substr($clear, $signatureLength + $ivLength)));
}
示例6: __construct
/**
* Constructor
*
* @param string $hash
*/
public function __construct($hash)
{
if (!is_string($hash)) {
throw new DataType('hash', 'string', $hash);
}
$hashInfos = password_get_info($hash);
if ($hashInfos['algo'] === 0) {
throw new DataFormat('hash', 'a valid password hash', $hash);
}
$this->hash = $hash;
}
示例7: saving
public function saving($model)
{
foreach ($this->options['fields'] as $field) {
$password = (string) $model[$field];
$info = password_get_info($password);
if ($info['algo'] === 0) {
// needs to be rehashed
$model[$field] = password_hash($password, $this->options['algo'], $this->options['options']);
}
}
}
示例8: setHash
public function setHash(string $hash) : PasswordInterface
{
if (empty($hash)) {
throw new PasswordException('hash is empty');
}
if (password_get_info($hash)['algo'] === 0) {
throw new PasswordException('The hash is not understandable by the underlying library');
}
$this->hashed = $hash;
$this->isHashed = true;
return $this;
}
示例9: __construct
public function __construct($hashedPassword)
{
if (!is_string($hashedPassword) || empty($hashedPassword)) {
throw new HashedPasswordException('The hashedPassword must be a non-empty string.');
}
$info = password_get_info($hashedPassword);
if (empty($info) || !isset($info['algo']) || empty($info['algo'])) {
throw new HashedPasswordException('The given hashedPassword (' . $hashedPassword . ') is invalid.');
}
$this->hashedPassword = $hashedPassword;
$this->algo = $info['algo'];
}
示例10: canUpgradeInternalHash
protected function canUpgradeInternalHash(PhutilOpaqueEnvelope $hash)
{
$info = password_get_info($hash->openEnvelope());
// NOTE: If the costs don't match -- even if the new cost is lower than
// the old cost -- count this as an upgrade. This allows costs to be
// adjusted down and hashing to be migrated toward the new cost if costs
// are ever configured too high for some reason.
$cost = idx($info['options'], 'cost');
if ($cost != $this->getBcryptCost()) {
return true;
}
return false;
}
示例11: test_password_get_info
/**
* password_get_info() test
*
* Borrowed from PHP's own tests
*
* @depends test_bootstrap
*/
public function test_password_get_info()
{
$expected = array('algo' => 1, 'algoName' => 'bcrypt', 'options' => array('cost' => 10));
// default
$this->assertEquals($expected, password_get_info('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y'));
$expected['options']['cost'] = 11;
// cost
$this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y'));
$expected = array('algo' => 0, 'algoName' => 'unknown', 'options' => array());
// invalid length
$this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100'));
// non-bcrypt
$this->assertEquals($expected, password_get_info('$1$rasmusle$rISCgZzpwk3UhDidwXvin0'));
}
示例12: getType
public static function getType($hash)
{
$info = password_get_info($hash);
if ($info['algo'] > 0) {
return $info['algoName'];
}
if (substr($hash, 0, 3) == '$P$') {
return 'phpass';
}
if (preg_match('/^[A-Z0-9]{32}\\:[A-Z0-9]{2}$/i', $hash) === 1) {
return 'salt';
}
trigger_error('OSC\\OM\\Hash::getType() hash type not found for "' . substr($hash, 0, 5) . '"');
return '';
}
示例13: password_needs_rehash
function password_needs_rehash($hash, $algorithm, $options = array())
{
$info = password_get_info($hash);
if ($info['algo'] != $algorithm) {
return true;
}
switch ($algorithm) {
case PASSWORD_BCRYPT:
$cost = isset($options['cost']) ? $options['cost'] : 10;
if ($cost != $info['options']['cost']) {
return true;
}
break;
}
return false;
}
示例14: verifyPassword
public function verifyPassword($password)
{
if (!defined('PASSWORD_DEFAULT')) {
require_once LIB_PATH . 'password_compat/password.php';
}
$this->loggedIn = password_verify($password, $this->PasswordHash) === true;
if ($this->loggedIn) {
// Verify password hash algorithm and strength requirements. -- cwells
$passwordInfo = password_get_info($this->PasswordHash);
if (password_needs_rehash($this->PasswordHash, PASSWORD_DEFAULT, $passwordInfo['options']) === true || $passwordInfo['options']['cost'] !== self::HASH_COST) {
// No need to verify success here since we'll try again on the next login. -- cwells
$this->setPassword($password);
}
}
return $this->loggedIn;
}
示例15: passwordHash
/**
* Get the password hash if it is plaintext.
* If hashed password is passed, so just returns it.
*
* @param RecoveryAccess|string $password Password to hash.
*
* @return string
*/
public static function passwordHash($password)
{
if ($password instanceof RecoveryAccess) {
$password = $password->password;
}
// Check password status.
// It should detect if is a hashed password.
$passwordStatus = password_get_info($password);
if ($passwordStatus['algo'] === 0) {
$hashOptions = [];
// Overwrite the default cost.
if (defined('VANILLA_RECOVERY_HASH_COST')) {
$hashOptions['cost'] = VANILLA_RECOVERY_HASH_COST;
}
return (string) password_hash($password, PASSWORD_BCRYPT, $hashOptions);
}
return $password;
}