Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffd5dd0

Browse files
committed
also allow stringable object for password
1 parent e755bb9 commit ffd5dd0

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private function getCredentials(Request $request): array
157157

158158
$request->getSession()->set(Security::LAST_USERNAME, $credentials['username']);
159159

160-
if (!\is_string($credentials['password'])) {
160+
if (!\is_string($credentials['password']) && (!\is_object($credentials['password']) || !method_exists($credentials['password'], '__toString'))) {
161161
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['password_parameter'], \gettype($credentials['password'])));
162162
}
163163

src/Symfony/Component/Security/Http/Tests/Authenticator/FormLoginAuthenticatorTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Security\Http\Authenticator\FormLoginAuthenticator;
2424
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
2525
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge;
26+
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
2627
use Symfony\Component\Security\Http\HttpUtils;
2728
use Symfony\Component\Security\Http\Tests\Authenticator\Fixtures\PasswordUpgraderProvider;
2829

@@ -129,7 +130,7 @@ public function testHandleNonStringUsernameWithToString($postOnly)
129130
/**
130131
* @dataProvider postOnlyDataProvider
131132
*/
132-
public function testHandleNonStringPasswordWithArray($postOnly)
133+
public function testHandleNonStringPasswordWithArray(bool $postOnly)
133134
{
134135
$this->expectException(BadRequestHttpException::class);
135136
$this->expectExceptionMessage('The key "_password" must be a string, "array" given.');
@@ -144,16 +145,24 @@ public function testHandleNonStringPasswordWithArray($postOnly)
144145
/**
145146
* @dataProvider postOnlyDataProvider
146147
*/
147-
public function testHandleNonStringPasswordWithInt($postOnly)
148+
public function testHandleNonStringPasswordWithToString(bool $postOnly)
148149
{
149-
$this->expectException(BadRequestHttpException::class);
150-
$this->expectExceptionMessage('The key "_password" must be a string, "integer" given.');
150+
$passwordObject = new class() {
151+
public function __toString()
152+
{
153+
return 's$cr$t';
154+
}
155+
};
151156

152-
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => 42]);
157+
$request = Request::create('/login_check', 'POST', ['_username' => 'foo', '_password' => $passwordObject]);
153158
$request->setSession($this->createSession());
154159

155160
$this->setUpAuthenticator(['post_only' => $postOnly]);
156-
$this->authenticator->authenticate($request);
161+
$passport = $this->authenticator->authenticate($request);
162+
163+
/** @var PasswordCredentials $credentialsBadge */
164+
$credentialsBadge = $passport->getBadge(PasswordCredentials::class);
165+
$this->assertSame('s$cr$t', $credentialsBadge->getPassword());
157166
}
158167

159168
public static function postOnlyDataProvider()

0 commit comments

Comments
 (0)