UserPassword
Edit this pageWarning: You are browsing the documentation for Symfony 2.1, which is no longer maintained.
Read the updated version of this page for Symfony 6.0 (the current stable version).
UserPassword
2.1
This constraint is new in version 2.1.
This validates that an input value is equal to the current authenticated user's password. This is useful in a form where a user can change his password, but needs to enter his old password for security.
Note
This should not be used to validate a login form, since this is done automatically by the security system.
Applies to | property or method |
Options | |
Class | UserPassword |
Validator | UserPasswordValidator |
Basic Usage
Suppose you have a `PasswordChange` class, that's used in a form where the user can change his password by entering his old password and a new password. This constraint will validate that the old password matches the user's current password:
- YAML
- Annotations
- XML
- PHP
1 2 3 4 5 6
# src/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Form\Model\ChangePassword:
properties:
oldPassword:
- Symfony\Component\Security\Core\Validator\Constraint\UserPassword:
message: "Wrong value for your current password"