I have an application running on Symfony2.0 with FOSUSerBundle. Every 3 months a user who connect the application have to change its password, it's in place and it's working.
Today every 3 months if the user write as new password the same as the previous one there is no verification and he can use it 3 more months.
I would like to add a constraints on the password reset and force the user to give a different password from the previous one. I have no idea how to do this. I tried to create a validator but i don't have my user ID in the validator...
Any clue?
I found a solution, It's working but I still have a small issue : when i submit my new password, if i try to put the same password as the previous one, my form is not valid (that's great !), but the error message is not shown by my twig whereas I'm using :
Any idea why?
Anyway here is my solution :
I added a validator on the class level to verify the password. To do so, i added a validator on my User class :
And i created a validator on the class level :
And :
I had the same problem with symfony 3.4. I solved (symfony doc) replacing your "return false" with this:
where
and cutting the "return true;" row at the end of your isValid function.
Another difference is that I used validate() function instead of your isValid()