I am using Symfony2 and need to save the failed login attempts to the database.
I have the following methods which I think I should be using:
// Symfony/Component/Security/Http/Autentication/AbstractAuthenticationListener.php
onFailure()
onSuccess()
But I am not sure how to access the database connection from within them.
How could run a database insert from within these functions?
You need to define your own failure handler in security.yml
Create a service to handle the failures
Then build your failure handler:
To save attempts to the database inject your Doctrine manager into the service and persist the attempt from within the onFail method.