Record failed login count in User attributes


Is it possible to save failed login attempts of a user in the user attributes, by creating for example a custom required action?
The use case is to save the failed login attempts (either through direct grant or browser flow) of a user in its user attributes so that keycloak admins can have these statistics.
This user attribute counter will need to be reset after user successful login

You could possibly tackle this with a custom event listener.
Example on

In the if statement where you check the type of event you can just do the following to set an attribute.

user.setSingleAttribute("attribute-key", "attribute-value");