I'm using Keycloak and I have implemented a custom authentication SPI to add a captcha to the login page. Additionally, I have implemented a user storage SPI for user validation. However, I would like the captcha to only appear when a user enters the wrong password for a specific username more than three times.
To accomplish this, I have set up a database table with two columns: "username" and "count". The "count" column keeps track of the number of failed login attempts for each username. I am looking for guidance on how to connect to this database within my custom authentication SPI. Specifically, I need assistance with the following:
How can I establish a database connection from within the authentication SPI? What is the approach to query the database and retrieve the count of failed login attempts for a specific username? How can I update the count to zero when the user successfully enters the correct password?
Thank you!