尝试抛弃验证码吧~

来源:互联网 发布:美少女跳舞源码 编辑:程序博客网 时间:2024/05/17 08:23

验证码作为防止表单垃圾信息普遍采用的方法,一直被广泛使用。但是同时它造成了很不好的用户体验,为合法用户的正常操作带来不便。本文介绍了一种抛弃使用验证码的方法,来防止自动垃圾信息的提交。
以前见过类似的方法,这几天开始学JQ,在中文版的《15天学会jQuery》上看到了作者有关的链接,简单翻译一下。

 

Make it difficult for spammers to probe our forms for weakness
Keep it easy for the “good guys” to use our contact forms
Therefore we need to avoid CAPTCHA’s
There’s research that indicates that they’re not as effective as once thought
We’ll borrow some concepts from Chris Shiflett, PHP security expert, and improve on them

使垃圾邮件发送者(通常是自动化程序——译者注)很难探测到我们表单的弱点
同时,保持让“好人(指正常访问的合法用户——译者注)”简单地使用我们联系方式的表单
因此,我们需要抛弃使用验证码的方法
有研究表明它们并不像当初想象的那样有效
我们将借Chris Shiflett(PHP安全专家)的一些概念,并加以改进

 

Specifically…
1.When the contact form is loaded we’ll make an AJAX call to a PHP file
2.The PHP file will grab the current time (according to the server, not the visitor’s browser)
3.The PHP file will combine the timestamp, plus a secret word, andgenerate a 32 character ‘hash’ and store it as a cookie on thevisitor’s browser
4.jQuery will receive the timestamp information from the AJAX call and store the hash or ‘token’ as a hidden form tag
5.When the form is sent for processing, the value of the timestamp willbe compared to the 32 character ‘token’ stored in the cookie
6.If the information doesn’t match, or is missing, or if the timestampis too old, we’ll kill execution of the form processor and a spammerlooking for easy prey will move on to another target

具体来说……
1、当联系方式表单被载入后,我们将制造一个到PHP文件的AJAX调用
2、该PHP文件将取得当前时间(依靠服务器,并不是访问者的浏览器)
3、该PHP文件将结合时间戳,加上一个加密的字,产生一个32位的“哈希”并把它作为cookie存储到访问者的浏览器上
4、jQuery将接收这个从AJAX调用来的时间戳信息,并将该哈希值或“令牌”作为表单的隐藏标签而存储
5、当该表单为处理而被发送,这个时间戳的值(表单中的——译者注)将和存储在cookie中的32位字符“令牌”做比较
6、如果信息不匹配,或是丢失,又或者时间戳过期,我们将终止表单处理的执行,同时这个垃圾邮件发送者将把目标转移到另一个简单的猎物上(放弃我们这个目标——译者注)

 

该文章是个手把手教程,上面只是前面的总述,但相信大家已经基本明白了。
不太明白的后面还有详细步骤及截图,这里就不翻译了:)

 

原文地址:http://15daysofjquery.com/examples/contact-forms/