我在网上发现了这个很棒的小代码,但它似乎没有正确删除空格后比较两个字符串?我知道一些js,但这里的任何错误都超出了我的理解。希望有人会知道这个答案。Javascript验证码
注意:它似乎也基于chs的数量来验证,而不是那些chs是什么,这些数字似乎不需要匹配,只要有足够的数字即可。
组织代码是由“mama21mama”,从“http://osticket.com/forums/showthread.php?t=6489&highlight=captcha”
我已经取得了一些小的个人修改,尝试修复它,下面是我的VR完成。
<script type="text/javascript">
function DrawCaptcha() {
var a = Math.ceil(Math.random() * 9)+ '';
var b = Math.ceil(Math.random() * 9)+ '';
var c = Math.ceil(Math.random() * 9)+ '';
var d = Math.ceil(Math.random() * 9)+ '';
var e = Math.ceil(Math.random() * 9)+ '';
var f = Math.ceil(Math.random() * 9)+ '';
var g = '10';
var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
document.getElementById("txtCaptcha").value = code
}
function ValidCaptcha() { // valida los numeros ingresados
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2){
return true; }
else {
return false; }
}
function removeSpaces(string) {
return string.split(' ').join('');
}
</script>
对我来说这似乎很好(输入数字,'ValidCaptcha'的结果被警告'输入的onblur'):http://jsfiddle.net/APzxv/5/ –
这似乎不是一个非常安全的验证码对我来说。人们可以轻松地重写'ValidCaptcha'来返回true。希望别人会对此表示赞同,因为我不是验证码专家。 –
以这种方式验证CAPTCHA客户端将意味着它很容易被绕过。相关评论:http://stackoverflow.com/questions/1998341/captcha-validation-with-javascript/1998361#1998361 – mattle