Add a Basic question Captcha
thekevinday - April 21, 2009 - 15:42
| Project: | CAPTCHA Pack |
| Version: | 6.x-1.0-beta2 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
I needed a question based captcha, so I created one.
All I did was stitch together code from the css captcha and the foo captcha then I made a very small number of modifications.
I have attached a patch that when applied to the root of the captcha_pack (patch -p1 -i ...), should add the question captcha to the captcha pack.
This idea can probably be improved on eventually by allowing multiple questions&answers and even cycling through them based on something.
But for now, I just went the simple approach of only 1 question and 1 answer.
This captcha should be useful for sites where the expected audience would know something specific that would not generally be known outside of that audience.
| Attachment | Size |
|---|---|
| captcha_pack-add_question_captcha-1.patch | 4.87 KB |

#1
This is an update to the patch, fixing some bugs and adding regular expression checking for more advanced checks.
#2
Hi, thank you for your work, I'll try to add it when I have more time to do this properly.
However, I am wondering about the name of the module.
"Question CAPTCHA" is not very descriptive because all CAPTCHAs ask a question :)
Some suggestions I could think of:
* "Generic question CAPTCHA"
* "Fixed question CAPTCHA"
* "Single question CAPTCHA" (which is not that good as a name, if you want to expand the functionality to a list of questions)
* "Plain question CAPTCHA"
* "Basic question CAPTCHA"
* "Ordinary question CAPTCHA"
English is not my mother tongue, so I'm not the best person to decide on this one, but I think I prefer "Ordinary question" and "Plain question".
#3
* "Fixed question CAPTCHA"
Sounds best, it is vague enough to be flexible in terminology but states exactly what it does.
--
There is a question I have about my programming on this CAPTCHA module.
When I added regular expression support, I was not certain how to do this through the main CAPTCHA project code.
My approach is a borderline hack, or so I suspect.
Instead of just returning the value the user submitted, I am exploiting the "preprocess" capability to do the regular expression check there.
I then return one of two strings "TRUE" and "FALSE".
The "generate" capability will read the "question_captcha_regex" variable and if the regex is being used, set the "$captcha['solution']" to be "TRUE".
Is this there a better or more correct approach?
Let me know if my wording is confusing.
#4
The problem with "fixed" is that it conflicts a bit when you would allow multiple question/answers.
---
About the prerocess stuff: I'm currently considering to drop that part from the API because it makes things more messy than it should. (#463002: Drop preprocess op of hook_captcha?)
Can you describe you use case in more depth, it is not very clear what you want to do with the regex'es. Do you want to do more advanced validation than a simple equality test?
#5
The problem with the question captcha is that a question can have multiple answers or multiple forms of one answer.
Lets take slug. If there were somehow a question that begged snail to be the answer and then it could have multiple forms, then the regex might be:
((land[[:space:]]*|())snail|slug)This regex accepts three main combinations:
- land snail
- snail
- slug
(and the [[:space:]]* allows for any amount of spaces or landsnail as a single word without spaces)
I could further extend this to handle the "scientific" names of the snail and the slug.
I can use the regex to pose multiple answers in a single text box.
My primary purpose is to allow for optionally making the answer more capable of handling tendencies of the user(s).
This is a yes to your question about needing more advanced validation capabilities.
#6
Interesting example.
FYI: from http://drupal.org/node/463002#comment-1602102:
#7
I created a feature request for custom CAPTCHA validation functions:
#473002: Provide a way to define custom CAPTCHA validation