Skip to content

Commit

Permalink
Merge pull request #4 from rjwebdev/username-validator
Browse files Browse the repository at this point in the history
Password may not contain username
  • Loading branch information
JanDC authored Oct 14, 2019
2 parents 43df4b8 + ec107a7 commit 233fac4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Constraints/PasswordValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function validate($value, Constraint $constraint)
->addViolation();
}

if (null !== $plainPasswordAccessor && $value->getUserName() === $stringValue) {
if (null !== $plainPasswordAccessor && false !== strpos($stringValue, $value->getUserName())) {
$this->context
->buildViolation($constraint->usernameMessage)
->setInvalidValue($value)
Expand Down
11 changes: 11 additions & 0 deletions tests/src/Constraints/PasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public function testNotEqualsUserName()
$this->assertSame($passwordConstraint->usernameMessage, $this->context->getViolations()->get(0)->getMessageTemplate());
}

public function testNotContainsUserName()
{
$user = new Symfony\Component\Security\Core\User\User('[email protected]', '[email protected]');
$passwordConstraint = new Password(['plainPasswordAccessor' => 'getPassword', 'plainPasswordProperty' => 'password']);

$this->validator->validate($user, $passwordConstraint);

$this->assertSame(1, $this->context->getViolations()->count());
$this->assertSame($passwordConstraint->usernameMessage, $this->context->getViolations()->get(0)->getMessageTemplate());
}

public function testLength()
{
$user = new Symfony\Component\Security\Core\User\User('[email protected]', 'Foo1');
Expand Down

0 comments on commit 233fac4

Please sign in to comment.