Skip to content

Commit bcda44d

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 5cbe67d commit bcda44d

File tree

7 files changed

+9
-8
lines changed

7 files changed

+9
-8
lines changed

Authorization/Voter/RoleVoter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function vote(TokenInterface $token, $subject, array $attributes)
4141
$attribute = $attribute->getRole();
4242
}
4343

44-
if (!\is_string($attribute) || 0 !== strpos($attribute, $this->prefix)) {
44+
if (!\is_string($attribute) || !str_starts_with($attribute, $this->prefix)) {
4545
continue;
4646
}
4747

Encoder/Argon2iPasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function isPasswordValid($encoded, $raw, $salt)
8383
{
8484
// If $encoded was created via "sodium_crypto_pwhash_str()", the hashing algorithm may be "argon2id" instead of "argon2i".
8585
// In this case, "password_verify()" cannot be used.
86-
if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I') && (false === strpos($encoded, '$argon2id$'))) {
86+
if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I') && (!str_contains($encoded, '$argon2id$'))) {
8787
return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded);
8888
}
8989
if (\function_exists('sodium_crypto_pwhash_str_verify')) {

Encoder/MessageDigestPasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function encodePassword($raw, $salt)
7373
*/
7474
public function isPasswordValid($encoded, $raw, $salt)
7575
{
76-
if (\strlen($encoded) !== $this->encodedLength || false !== strpos($encoded, '$')) {
76+
if (\strlen($encoded) !== $this->encodedLength || str_contains($encoded, '$')) {
7777
return false;
7878
}
7979

Encoder/NativePasswordEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public function isPasswordValid($encoded, $raw, $salt): bool
9797
return false;
9898
}
9999

100-
if (0 !== strpos($encoded, '$argon')) {
100+
if (!str_starts_with($encoded, '$argon')) {
101101
// BCrypt encodes only the first 72 chars
102-
return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded);
102+
return (72 >= \strlen($raw) || !str_starts_with($encoded, '$2')) && password_verify($raw, $encoded);
103103
}
104104

105105
if (\extension_loaded('sodium') && version_compare(\SODIUM_LIBRARY_VERSION, '1.0.14', '>=')) {

Encoder/Pbkdf2PasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function encodePassword($raw, $salt)
8080
*/
8181
public function isPasswordValid($encoded, $raw, $salt)
8282
{
83-
if (\strlen($encoded) !== $this->encodedLength || false !== strpos($encoded, '$')) {
83+
if (\strlen($encoded) !== $this->encodedLength || str_contains($encoded, '$')) {
8484
return false;
8585
}
8686

Encoder/SodiumPasswordEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function isPasswordValid($encoded, $raw, $salt): bool
8484
return false;
8585
}
8686

87-
if (0 !== strpos($encoded, '$argon')) {
87+
if (!str_starts_with($encoded, '$argon')) {
8888
// Accept validating non-argon passwords for seamless migrations
89-
return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded);
89+
return (72 >= \strlen($raw) || !str_starts_with($encoded, '$2')) && password_verify($raw, $encoded);
9090
}
9191

9292
if (\function_exists('sodium_crypto_pwhash_str_verify')) {

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": ">=7.1.3",
2020
"symfony/event-dispatcher-contracts": "^1.1|^2",
21+
"symfony/polyfill-php80": "^1.16",
2122
"symfony/service-contracts": "^1.1.6|^2"
2223
},
2324
"require-dev": {

0 commit comments

Comments
 (0)