DavidL
unread,Mar 16, 2023, 3:24:43 PM3/16/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to py4web
Here is my very rudimentary captcha to stop my registration page getting spammed by bots. Can probably be easily cracked by a good bot, but might just help for a low key site. Let me know any feedback
In common.py add a new field to auth_user as well as a validator.
from . import human
def human_test(val, error):
e = human.check(val)
return val, e
auth.extra_auth_user_fields = [Field('prove_you_are_human', length=10, validate=human_test)]
e in the above is should be False if the user passes the test, otherwise it should be the message you want them to see e.g. "please try again". val is the value entered in the prove_you_are_human field.
The simple logic of the problem the human must solve is in the module human.py (whose contents I won't divulge, you'll need to create your own). This module also has a function "question()" which generates the prompt for the user.
Change templates/auth.html so instructions are provided on the problem to solve below the registration form. The "if" statement, determines which auth pages the prompt will appear in.
<div class="auth-container">
[[=form]]
[[if "register" in locals()["request"].url or "profile" in locals()["request"].url:]]
[[from apps._default import human]]
<div class="box has-background-light">
<p class="label">Prove That You are Human: complete this task:</p>
<div class="box">
<center><p class="label has-text-info is-size-4 has-text-centered"><b>[[=human.question()]]</b></p></center>
</div>
</div>
[[pass]]
</div>