Hi
I spend some time on the captcha module and ended up rewriting a lot of code. In attachment is a tar with captcha.info, captcha.module and captcha.install. (no patch file because too much changed).
Some highlights of what changed:
- The captcha_points are now stored in a table of its own (see captcha.install), instead of the kinky variable_set/variable_get stuff. I think working with variable_set/variable_get is a bad idea because form_id+user_role_name can get very long, while the variable key field is limited to 48 characters (see a http://drupal.org/node/145515). in the table I use only the form_id, and the field is 128 characters long, which should be enough I think.
- Only captchas for anonymous users: I can't imagine why you would want to present a captcha to a user that already logged in. There exist other and better techniques to limit the behavior of authenticated users (permissions, blocking). So only captcha's for anonymous users => less administration bloat => less code bloat.
- I don't use the form_store and form_collect stuff for collecting form_id's. I use a simple alternative: with hook_form_alter() I add a link "add a captcha to this form" to each form for administrators, which immediately leads to a captcha configuration page.
- The old administration pages "captcha" and "captcha points" are merged in one central captcha admin page
- The captcha's are placed above the submit button automatically
This "patch" should also fix issues http://drupal.org/node/145515, http://drupal.org/node/60874, http://drupal.org/node/103941, http://drupal.org/node/141478, http://drupal.org/node/142624, and probably more (I don't have time to check them all, I already spend more time on this than I planned)
I'm not familiar with modules that implement hook_captcha, so I don't know if my version is still compatible with these. But I didn't touch the hook_captcha() API to much, so I don't expect a lot of problems there.
feedback is welcome.
thanks
going to sleep now.
| Comment | File | Size | Author |
|---|---|---|---|
| #61 | captcha-r77.tar_.gz | 358.08 KB | soxofaan |
| #57 | captcha-r75.tar_.gz | 358.08 KB | soxofaan |
| #56 | captcha-r68.tar_.gz | 357.42 KB | soxofaan |
| #49 | captcha-r59.tar_.gz | 356 KB | soxofaan |
| #43 | captcha-r58.tar_.gz | 355.99 KB | soxofaan |
Comments
Comment #1
robloachI'll take a look at it and test it in a variety of different scenarios. As for your worries about hook_captcha, I'll test that out with recaptcha. Also, in the future, try to create a patch/diff when submitting code ;-) .
Comment #2
soxofaan commentedI know, but I added a file (captcha.install) and I couldn't add it to my CVS working copy because I have no commit permission (with SVN this would be possible though). Consequently I couldn't get a diff patch with the new file included.
But on that CVS info page you mentioned (http://drupal.org/patch/create) there is a workaround for it.
In attachment: my work as a diff patch.
thanks for testing
Comment #3
soxofaan commentedin attachment: a small additional (incremental) patch for my module rewrite that solves minor bugs
Comment #4
soxofaan commentedin attachment an additional (incremental) patch with some cosmetic changes: changed some UI strings, updated queries to drupal code convention, minor t() changes.
No functionality was changed
Comment #5
soxofaan commentedIn my previous additional patch (captcha-r12.patch) there is a stupid syntax error, do not use it.
Use the patch from this reply (captcha-r13.patch)
Comment #6
soxofaan commentedI did some further research and this patch should also solve issues http://drupal.org/node/148220 (added an option for this) and http://drupal.org/node/148220
Comment #7
soxofaan commentedYet another additional patch: solved minor bug in installation procedure and added some default form_ids
Comment #8
Farreres commentedI didn't try your patches, but I saw a new version today, does it reflect the patches or is it only a minor update? Will you please warn when your patches are applied? I totally agree with your oppinions and the modifications you say you did. I would really enjoy having this in a stable release.
Comment #9
wundo commented@7
I'm commiting part of your patch.
Would be better if you add some comments to your code. ;)
And I'd prefer if you do just one fixes/feauture by patch and if you break issues like that in many parts :)
thanks soxofaan
Comment #10
wundo commentedSorry, but I prefer keeping form store dependency, isn't captcha function to discover forms.
Comment #11
wundo commentedComment #12
soxofaan commentedWell, the original captcha.module does not contain much comments either ;), but that's not a reason to neglect it myself.
I understand, but because I had to change so much (going from set_variables/get_variables to a dedicated table is not that trivial), I decided to do a big rewrite.
I understand. It isn't indeed captcha function to collect forms, but because I introduced the table
captcha_pointsthe form_store functionality had no use anymore (only administration overhead).But I'll look more into this, and look if I can't "outsource" some functionality to form_store again.
Thanks for your time
Comment #13
monkeybeach commentedThere's a show-stopping error in the install file:
[code]description varchar(256) NOT NULL,[/code]
should only be 255 max.
Also this simply doesn't work for me. Once I'd changed the SQL error and got things installed, I could do administrative tasks, but the CAPTCHA never appeared on the contact form (standard drupal contact module) I wanted it to.
I did get an error message about captcha.module line 180, but I'm afraid I've not been able to replicate it.
Looking good though. If the bugs can be ironed out this looks much nicer than the current version.
The main feature I'm after is the more logical positioning since the current module is a bit crap at that.
Comment #14
soxofaan commentednote that captcha's are only presented to anonymous users and not authenticated users, so be sure to log out to test it (or use another browser/client). When "Add captcha adminstration links to forms" is enabled, users with the "administer site configuration" role should see some adminstrative message on the place of the captcha though.
thanks for testing
Comment #15
monkeybeach commentedOops! :)
Yup, that got it. Although I've still having to manually apply the sql via PHPMyAdmin as the install file doesn't add the table to the database.
Could be it's another obvious error on my part though.
Comment #16
robloachThe recent Captcha version 2.2 breaks the API. reCAPTCHA always returns TRUE.
Comment #17
soxofaan commentedI looked into this and reworked my version of the captcha module. I slimmed down the captcha_points table to only two fields: form_id and captcha_type. These are the bare essentials for the baseline captcha functionality. Extra attributes (like a description or visibility) should be implemented by the form_store module. I reworked the module code to fit the reduced table. I kept the "captcha administration links" functionality, because it is not that much code but offers a lot more usability (aka "less clicking") for the captcha module than the form_store can/will provide.
During testing my module, I observed that I don't need the form_store module anymore. So I think we can drop the form_store module as a dependency (it is not a real dependency, but for the original module it is needed if the default captcha points are not enough). I think it is a good thing to have less dependencies.
Consequently I did not implement calls to form_store functionality in my version. It is possible though to do it, but I don't see real benefits worth the hassle.
In attachment is the diff patch between CVS version 1.42 of captcha.module and my last version (revision 15, I keep my code in a bazaar repository btw). This patch overrules all previous patches in this thread/issue (it is not incremental).
bye
Comment #18
soxofaan commentedOk, it's late, I should go to sleep
ignore the patch file from my previous post (#16)
and use the one from this post
(which does not contain a stupid syntax typo) ;)
Comment #19
wundo commented@rob,
Contact me in pvt to solve that please. ;)
Comment #20
soxofaan commentedHi again,
I worked further on my rewrite of the captcha module. I'm at revision 30 now (I branched from CVS version 1.41). Because there changed so much, it does not make really sense to post a diff between CVS1.41 and my version (the diff is bigger than the new version on its own). On the other hand, I understand that the module maintainer(s) do not want to overwrite the existing version with my version just like that.
In attachment i've put a tar.gz with the best of all worlds:
captcha.module,captcha.installandcaptcha.infofor people that want to test, but don't want to do the patching and have no problem with overwriting the existing module. It's possible that it's needed to do an install-uninstall-install (or something) of the module, because the existing version does not use a install file and my version does (I think). I guess that's the problem monkeybeach mentions in #15. I had the problem too the first time after i added the install file.patchesfor the incremental changes between my 30 revisions (starting from CVS1.41).The file
captcha-rewrite.logcontains the revision log of the incremental changes.1 patchfile for the diff between CVS1.41 and my last revision (30).
The most important changes since my previous post are roughly:
I hope most of my work will make it to the official version
sincerely
soxofaan
Comment #21
Tresler commentedI realize I am a day late and way short.... but if we are having that many issues with this module that we are re-writng it frm scratch - is it worth merging/converting to Heine's MyCaptcha module http://heine.familiedeelstra.com/mycaptcha-download
I finally hit the wall with captcha - where too many users were complaining that it didn't work and tried it. Sorry I didn't get to this sooner just seems like we are duplicating effort here.
Comment #22
soxofaan commentedWell, I didn't start writing it from scratch, I just started rewriting parts of it. But in the end, nothing much has been left over from the original module :)
Will MyCaptcha be hosted on drupal.org? If so, I'm in favour of merging/unifying/streamlining things (captcha, recaptcha, captcha riddler, textimage, mycaptcha, my patches,...). I have not much experience with mycaptcha, but at first sight it looks a bit more advanced that what I tried to make because of the image captcha generation.
With this in mind, we could maybe create a captcha_light (or captcha_basic or wathever) out of my rewrite? It's light because there are no dependencies, but it's very functional and usable however. Heine's MyCaptcha could then depend on captcha_light and implement the image captcha stuff and replace or use the textimage functionality?
it is indeed a frustrating situation. Certainly in this era of spam.
I hope we don't. That's why I report as much as possible in this thread (and put shameless self-advertisements in other captcha issue threads :) ). I just wanted to create a simple but usable (only captcha's for anonymous visitors, simple text challenges, no dependencies, no form_store, no images) captcha module. MyCaptcha looks a bit more ambitious.
I hope this gets cleared out soon.
Comment #23
wundo commentedMaybe it's better to move this discussion to captcha group. ;)
Besides me someone tried soxofaan patch?
Comment #24
phillipadsmith commentedTried #22 and A) didn't get a captcha added to my "Webform" (http://drupal.org/project/webform) and B) have this error on the top of that page now:
Notice: Undefined property: theme in /usr/local/www/drupal/includes/theme.inc on line 45
Comment #25
phillipadsmith commentedAlso... tried to revert back to my previous version of captcha module and now get a page not found at /admin/settings/captcha
Comment #26
soxofaan commentedDid you enable "Add captcha adminstration links to forms" in the captcha settings?
Then, did a "Captcha administration" link show up on the webform?
Then, did you click on that link? What was the highlighted form_id?
After the administration phase, did you try to visit the webform as anonymous user?
Authenticated users wont see any captchas, only users with administrative priviliges will see an indication that there will be a captcha.
weird, I don't see anything related to captcha on that line.
clear your menu cache (e.g. use the devel module http://drupal.org/project/devel)
sometimes visiting the menu administration page also helps: e.g. example.com/?q=admin/build/menu
thanks for testing
Comment #27
Farreres commentedJust an oppinion, I don't know if it is the place for it, or the groups area. I have been using captcha for several months now, and I consider it a cornerstone or starting point for adding security to a web page. Since I have been using this module, it has the serious bug of validating before submitting. I don't know if such a big rewrite is what the maintainer had in mind, but if this solves the problems and makes the module more usable (joining all management screens in one) it should be given a try. Just a user oppinion. It is time to have a captcha that works fine.
Comment #28
phillipadsmith commentedHey there soxofaan
Yes to all of the above.
Weird, indeed. :-)
Yep -- figured that out shortly after.
Many thanks for the follow-up. Happy to re-test.
Comment #29
soxofaan commentedhello phillipadsmith (in #28):
I tried the webform module and apparently there are two ways to enable a captcha:
hook_captchachallenge) from captcha API (which is not stable/decided upon yet). This does not work of course.happy to help
Comment #30
taqwa commentedFor some reason this file doesn't work for me after I patch it. Could you please submit a pre-patched version? Thanks!
Comment #31
soxofaan commentedHere is a new version (revision 37) of my rewrite. I think it doesn't make sense anymore to provide all the (37) patches (like I did before), so I just attached a tarball as if it would be a normal module.
changes since revision 30:
bye
Comment #32
soxofaan commentedit is possible that you need to do an "install" after "uninstall" after "install" of the rewrite if you had the official captcha module already installed.
Comment #33
soxofaan commentedHere is another version of my rewrite (revision 52)
Main changes:
cache_captchatable needed, better integration with base captcha module.please try it
and give feedback
bye
Comment #34
soxofaan commentedHere I am again with a new version (revision 56)
Main difference: added documentation about the API for developers that want to implement their own captcha challenge and integrate nicely with the base captcha module
Comment #35
jnm-1 commentedthe new file isn't valid. (ark is complaining).
By the way, great rewrite, it works! (and the original one didn't anymore). In my opinion it should replace the original one or get a place somewhere else on drupal.org.
Comment #36
Farreres commentedAgain, I agree with jnm. I didn't try this module because it is too complicated for me to patch, but it seems this rewrite works, from the comments I see. Please, it is about time for us to have a working captcha. I don't think dividing efforts is worth. Please, get the new code as the base one, it's a much better option than offering two captcha modules, one working incorrectly and a correct one which is a rewrite of the first. Just join the good code of both and offer us users a final working captcha module, please!
Comment #37
skor commentedseems like the file is only tar file, not zipped, as the filename implies.
Comment #38
skor commentedOK, I un-installed 5.x-2.2 and form_store module. removed my sites/all/modules/captcha directory
Downloaded and extracted the tar file from post #34 and enabled just the basic captcha module (also ran update.php, but didn't see any required updates).
On the captcha settings page, I enabled "Add captcha adminstration links to forms", but I didn't get a link on any forms.
Am I missing something?
I even emptied the cache and reset menus, just to be sure. Still no luck.
Comment #39
soxofaan commentedAgain a new version of my rewrite (revision 57)
Main change (beside a UI text typo) is that I worked on the upgrade path for users of the original captcha module. Upgrading (from the original captcha module, not from previous version of my rewrite) is now how it should be: replace old version with new version, run update.php script and done. So, no install-uninstall-install cycle needed, no error messages to ignore, like it was with previous version of my rewrite.
Upgrading from previous versions of my rewrite will possibly generate errors during the update, I guess, but i't safe to ignore them. Uninstall and reinstall if you want to be sure to have a working version.
complete module tarball in attachment (now with gzip compression ;) )
jnm, Farrerres, Skor,
thanks for your feedback
Comment #40
soxofaan commentedCaptcha administration links are only visible to users with the "administer site configuration" permission. Moreover you won't see captcha administration links on forms in the administrative section (?q=admin/foo/bar). Could it be related to this?
Do the default installed captcha points work? You don't need the captcha administration links for working with these default captcha points.
Also note that captcha's will only be visible to anonymous visitors. So to test, log out or use another browser/client/computer.
Comment #41
heine commentedYou forgot the install hook in captcha.install :)
Comment #42
GoofyX commentedComment regarding captcha-r57.tar_.gz.
I've installed it in a Drupal 5.1 installation, which never had any captcha module installed. I first activated the core module (captcha) and afterwards the other two (Image captcha and Text captcha). After visiting captcha's administration settings page, I get the warning:
Maybe this is related to Heine's #41 comment?
Comment #43
soxofaan commentedyep, stupid me. should have read the documentation on hook_install better.
revision 58 in attachment should solve this issue
sorry guys
Comment #44
skor commentedLooks good so far. Though I've only tested out math captcha on user registration and password reset, both correct and incorrect responses.
Comment #45
skor commentedLooks really good. Now I've checked out text & image captchas, removed and added some captchas to some other forms.
I still haven't played with any of the text or image settings yet, but basic functionality all looks good.
Comment #46
heine commentedUsing one session variable per form_id won't do. This breaks requesting multiple comment submission forms in tabs, then submitting or previewing them.
Comment #47
soxofaan commentedI know, it's on the todo list (see top of captcha.module file).
Comment #48
soxofaan commentedWell, you could store the solution of each requested captcha in the $_SESSION variable (with a different random captcha_token as key), so anonymous users can post multiple instances of the same form at the same time. I'm working on a patch for this.
But the problem is that a malicious user could keep requesting forms (and captcha's) without solving them. Doing so, he can spam his session variable which leads to pollution of the database and maybe unneeded overhead. A solution to this could be to flush the session variable if too many (e.g. 20) captcha's are unsolved.
Comment #49
soxofaan commentedHere you are, a new version (revision 59). Anonymous users now can request up to 10 instances of the same form before submitting them. If more than 10 instances are requested, all previous challenges for that form are flushed.
The threshold 10 seems a reasonable default to me. Plenty for normal human users, but small enough to a be some sort of annoyance for spammers. I decided to not make this threshold configurable in the interface, because it doesn't seem worth it. It's a "php define" constant at the top of captcha.module however, so not too hard for power users to tweak it. Any toughts?
Comment #50
robloachI tried it out and have a few comments:
I think we should consider replacing the current version of Captcha with this version. I'll talk to wundo and see what he thinks.
Comment #51
robloachJust an idea for the permissions I was talking about. You could have a "bypass captcha" permission in captcha_perm that allows the role to skip the captcha authentication. This means that although logged in, untrusted, users have to use captcha, the logged in trustworthy moderators of the site don't have to use it.
Comment #52
soxofaan commentedI'll add this, thanks.
Of what revision of my rewrite are you talking? In my latest revision (59) I implemented the upgrade path from the previous captcha version. Or doesn't that work for you?
In my opion, captchas should only be used on anonymous users. There exists much better/more efficient ways to control the behavior of authenticated users: user permissions, roles, tracking, blocking, etc. It doesn't make sense to have an option to offer a captcha to site administrators for example. Also, I think offering a captcha selection for each form and for each role (like the currently official captcha module) adds too much bloat to the captcha configuration page and administrative overhead without sensible value. There are bug reports out there complaining about having to handle thirty-something selection boxes (e.g. six user roles x five forms). That's why I removed the user roles stuff from my implementation.
Thanks for your feedback
Soxofaan
Comment #53
robloachBut the problem is that once a spammer logs in, they can initiate their spam bot and be free to post anything anywhere since the Captcha isn't enabled on authenticated users. I actually encountered this on my personal site. I had the spam control enabled only for anonymous users, and assumed that everyone that was creating an account was human. It turned out I started getting countless account registerations, as well as spam comments everywhere. Yes, you can enable it on the user login and registeration form, but that doesn't stop them once they log in, and initiate their spam bot.
The solution I am offering wouldn't break the system; all it would add is more functionality. Fundamental functionality of a Captcha system, in my opinion. It wouldn't bloat the user interface either, as it would just be one permission in the user access page (you should also have "administer captcha" in there as well). If you don't implement it, I will, as it's a required component of the system I'm developing.
Comment #54
David Goodwin commentedHi,
1) Thank you for trying to fix the captcha module; I'm pissed off with having to delete comments from my moderation queue that shouldn'd be there (esp. the one with the subject of 'people')!
2) Installed it fine - update.php did it's DB stuff etc etc.
3) Tried to change the word pool to a user defined one with stupid (but intelligible) words; it wouldn't play ball.
Using -r59.
thanks
David.
Comment #55
Eleazar commentedThank you! This blows the "officia" captcha module out of the water. This module is brilliant and without a doubt should be standard for Drupal. Thanks!
Comment #56
soxofaan commentedYet another new release (revision 68). Changes:
to base and sub modules.
thanks for testing guys.
Comment #57
soxofaan commentednew release (revision 75). Changes:
Comment #58
robloachIn order to make it so that people can submit patches to your branch, I put your implementation of Captcha in the CVS at contributions/sandbox/robloach/captcha:
http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/robloach/capt...
I have a few things I'd like to work on and patch, and I'm sure that other people would like to do so as well. This will make it much easier to collaborate on this branch. If you have a patch, feel free to commit it directly, or post the patch/diff here.
My current goal is to add the "skip captcha" or "bypass captcha" permission.
Comment #59
heine commentedI'm marking this fixed for now as all the remaining issues can be posted against 5.x-3.x
Comment #60
robloachAs per the discussions with Heine and Wundo, this has been moved to the DRUPAL-5--3 branch...
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/captcha/?only...
Comment #61
soxofaan commentedIt seems that my revision 59 (or maybe older) is in that CVS branch currently, while in robloach's sandbox it is revision 75. Why?
in attachment: revision 77 of my rewrite, which adds the 'skip captcha' permission stuff and related changes in code/documentation/UI. Individual patch against revision 75 is at http://drupal.org/node/158305#comment-272823
thanks for committing it to CVS
Comment #62
wundo commentedWe do not completely agree with some feautures that were implemented after r58.
For example the 10 different captchas limit, etc.
There is an discussion in capcha group about that.
Cheers,
Fabiano Sant'Ana
Comment #63
wundo commentedPS: Please submit futher changes as patches and please open new issues. (And always try to keep just one change by issue)
Thank you for your work,
Fabiano Sant'Ana
Comment #64
skor commentedAre you going to put what's in CVS out as a 5.x-3.x-dev branch? That would make it easier to tag the patches to the version.
Comment #65
robloachOnce we test a bit more with what's in there, we'll push a release. Should be within the next few days.
Comment #66
soxofaan commentedI don't find that captcha group discussion, or do you mean the discussion about the role/permission stuff?
Considering the "10 different captchas limit": is it to limited? unneeded? I'd like to have your opinion. I'd also like to know the other 'disagreements'.
Don't hurry, I'd like to push some features from after r58 (e.g. playing nice with caching, cleanup on uninstall, the 'skip captcha' permission).
cheers
Comment #67
soxofaan commentedHere are already some patches (bugs, small features) that shouldn't be a problem: http://drupal.org/node/158734 (about page caching), http://drupal.org/node/158740 (bug in text_captcha settings valdation), http://drupal.org/node/158747 (minor issue with image placement in image_captcha), http://drupal.org/node/158736 (cleanup on uninstall as suggested by Rob Loach), http://drupal.org/node/158305 (basic implementation of 'skip captcha' permission).
Comment #68
(not verified) commented