You pass the model (hopefully ViewModel). Why not add NumberOfFailedLogins to it?
Then you could just put some code around Recaptcha saying
<%: if (Model.NumberofFailedLogins > 3) { %> <%: ReCaptcha.GetHtml(publicKey: "thisismykey", theme: "red") %> <% } %>
NOTE. I use Razor syntax, so I apologize if the above is not ideal. I'm sure you got this idea!
Obviously, you need to update NumberOfFailedLogins backstage!
EDIT: Just to clarify, the number of failed login attempts should be recorded in the membership database backstage automatically (the action of the login attempt should do this, note that the ASP.NET Membership Provider automatically records the number of consecutive failed login attempts out of the box), and it is from there that the ViewModel gets this information. Therefore, it doesnβt matter if you use a bot to try to harm your path, it can still be represented using ReCaptcha after three attempts (and, of course, it can be blocked if necessary).
Tom chantler
source share