I've developed a simple app with a single button that triggers different text changes. My aim is to distinguish between human users and potential bots. If the clicks happen too rapidly, it's likely a bot, and that's when I'd want to present a ReCaptcha.
My approach involves monitoring the time intervals from the first button click and the subsequent ones over a 5-minute window. If the clicking maintains an extremely consistent speed, say, a click every 10 milliseconds, it's a red flag for potential bot activity. Humans typically can't sustain such robotic precision, whether the interval is 10 milliseconds, 1 second, or 2 seconds.
Now, what I'm confused about is, is this method correct? And if so, what could be done (in code)?
Here is a Screenshot.
frameLayoutBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(animation);
ClickCounter++;
catStr = getCatTextFromDatabase(ClickCounter);
if (ClickCounter > 1000) {
CountText.setText("Count:" + ClickCounter);
}
if (catStr != null && !catStr.isEmpty()) {
CatText.setText(catStr);
}
}
private String getCatTextFromDatabase(long counter) {
DatabaseHelper dbHelper = new DatabaseHelper(getApplicationContext());
return dbHelper.getTextForCounter(counter);
}
});
I have never actually used something like this in a productive environment, but I would suggest two things:
nclick times (or times between clicks) in aCollectionor helper class that at the point of adding automatically disposes of older, now irrelevant entries. I likejava.util.Stackin helper classes with similar purposes.Edit:
Maybe something like this, although I couldn't be bothered to implement standard deviation or similar. Feel free to replace methodology within
valid()with any given statistics or replace theStackwith a collection of your choosing. You would hvae to replace thepop()withremove(size()-1)though.As it stands, this would return false if you
add()a time between clicks that is unrealistically small (as defined in the constructor) and returns the assessment of it being a bot withvalid()periodically.It would also be smart to not recalculate min mean an max like that because that takes time.