Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPCompatibility\AbstractFunctionCallParameterSniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Utils\PassedParameters;

/**
* The constant value of the password hash algorithm constants has changed in PHP 7.4.
Expand All @@ -34,16 +35,22 @@ class NewPasswordAlgoConstantValuesSniff extends AbstractFunctionCallParameterSn
/**
* Functions to check for.
*
* Key is the function name, value the 1-based parameter position of
* the $algo parameter.
* Key is the function name, value an array containing the 1-based parameter position
* and the official name of the parameter.
*
* @since 9.3.0
*
* @var array
*/
protected $targetFunctions = [
'password_hash' => 2,
'password_needs_rehash' => 2,
'password_hash' => [
'position' => 2,
'name' => 'algo',
],
'password_needs_rehash' => [
'position' => 2,
'name' => 'algo',
],
];

/**
Expand Down Expand Up @@ -94,14 +101,14 @@ protected function bowOutEarly()
*/
public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters)
{
$functionLC = \strtolower($functionName);
if (isset($parameters[$this->targetFunctions[$functionLC]]) === false) {
$functionLC = \strtolower($functionName);
$paramInfo = $this->targetFunctions[$functionLC];
$targetParam = PassedParameters::getParameterFromStack($parameters, $paramInfo['position'], $paramInfo['name']);
if ($targetParam === false) {
return;
}

$targetParam = $parameters[$this->targetFunctions[$functionLC]];
$tokens = $phpcsFile->getTokens();

$tokens = $phpcsFile->getTokens();
for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) {
if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ $hash = password_hash( $password, PASSWORD_DEFAULT, $options );
$hash = password_hash( $password, PASSWORD_BCRYPT, $options );
$hash = password_needs_rehash( $password, PASSWORD_ARGON2I, $options );
$hash = password_hash(
$password,
password: $password,
options: $options
// comment.
PASSWORD_ARGON2ID,
$options
algo: PASSWORD_ARGON2ID,
);

// Undetermined. Ignore.
Expand All @@ -20,7 +20,7 @@ $hash = password_hash( $password, static::ALGO, $options );
$hash = PassWord_hash( $password, null, $options );
$hash = password_hash( $password, +1, $options );
$hash = password_needs_rehash( $password, 2, $options );
$hash = password_hash( $password, 3, $options );
$hash = password_hash( algo: 3, password: $password, options: $options );
$hash = password_hash( $password, '2y', $options );
$hash = password_HASH( $password, "argon{$type}" /*comment*/, $options );
$hash = password_needs_rehash( $password, 'argon2id', $options );