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);
}
});
In this code:
We use a lastClickTime variable to store the time of the last click.
The maxInterval variable represents the maximum allowed time interval between clicks. In this example, it's set to 100 milliseconds, but you can adjust it according to your needs.
When the button is clicked, the code calculates the time interval since the last click and checks if it's less than the maxInterval. If the interval is shorter than the allowed maximum, you can implement your CAPTCHA logic or any other action to deal with potentially automated behavior.