jamesturk/django-honeypot

More info on HONEYPOT_VERIFIER and how to implement time based honeypot

Zerokami opened this issue · 3 comments

I want to implement time stamp based verification. i.e, if the form is submitted too fast I want it to be invalid.

In other words I want a custom validator.

You say in reademe that this is possible, but I'm unable to figure out how.

Please direct me to the method to achieve this.

Thanks!

If you set HONEYPOT_VERIFIER & HONEYPOT_VALUE to callables:

HONEYPOT_VALUE = lambda: datetime.datetime.now()
HONEYPOT_VERIFIER = function_that_checks_datetime_is_recent

you can implement whatever custom validation you want

Please, show for example how do you check HONEYPOT_VERIFIER? I can't understand

For anyone who happens on this in the future:

HONEYPOT_VERIFIER is a function that receives one argument (the field defined in HONEYPOT_FIELD).

So, if you wished to have a form that validates that it was submitted 15 seconds after the original timestamp you'd use something like this:

HONEYPOT_VERIFIER = lambda x: (int(datetime.datetime.timestamp(datetime.datetime.now())) - int(x)) > 15

x in this case is passed via the verification function (located in decorators.py.

Hope this helps!