使用JavaScript验证CAPTCHA

时间:2010-01-04 09:02:33

标签: javascript captcha

我正在尝试使用JavaScript验证Captcha。但我找不到任何有关Captcha的Client API的资源。你有文件吗?

5 个答案:

答案 0 :(得分:14)

如果您可以通过JavaScript验证验证码,这意味着找到有效代码的方法可以在您传递给客户端的代码中随时可用,这将有效地使完全用于验证码。

实现此目的的唯一安全方法是向服务器发送AJAX请求,然后验证代码。这样,您的验证将完全按照您通常验证服务器上验证码的方式完成。

答案 1 :(得分:2)

使用javascript验证验证码意味着您需要在您的html源中显示您的验证码文本的一些表示,这对于机器人是自动可见的。

我认为,如果你必须使用javascript进行验证,则可能是对验证码文本服务器端进行哈希处理,将其加载到javascript变量中,然后使用等效的javascript哈希函数进行验证。

答案 2 :(得分:2)

使用JavaScript验证CAPTCHA是一个坏主意,因为机器人可以轻松击败CAPTCHA。如果您的意思是想要进行Ajax调用以提交略有不同的输入文本。

答案 3 :(得分:0)

你可以使用它,它非常简单

myFunction();
var val=[];        
val.push("VQ7W3");     /** push value in this array  */
val.push("A1234");     /** To maintain image order here   */
val.push("A32BD");   /** if first image 0_capt.jpeg contains value VQ7W3 so push this value into zero(0) index of array   */
val.push("LD673");
val.push("PQ78V");
val.push("MX81W");
var x;
/**This below method generate random number from 0-5
 * name of image starts with that number will set on 
 * captcha location 
 */
function myFunction() {
    x = Math.floor(Math.random() * 6);     // here 6 stand for how many images you are using return 0-6 number.
	$("#imgCaptchaPlace").html("<img id='abc' src='captcha_images/"+x+"_cpt'/>")  ;   
}

/**
 * This below method will call on change of input fields where user enter
 * captcha code value
 */
function chaeckCpatch(id)
{
		if($("#"+id).val()==val[x])
		{
				alert("match");
		}
		else
		{
			alert("No match");
		}
	
}
  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<body>
<!--  below div use to display captcha image -->
<div id="imgCaptchaPlace"></div>

<!-- below textfield where user enter captcha value -->
<input type="text" id="captchaText" onchange="chaeckCpatch(this.id);"/>

<!-- include this JS file -->
<script src="captchByAarif.js" type="text/javascript"></script>
</body>
</html>

  

您可以下载此示例中使用的验证码图像

https://github.com/aarifa-ds/Captcha-Code

  

答案 4 :(得分:-1)

正如概念证明...... 如果您将验证码字符串的HASH发送到浏览器。你可以动态地HASH用户输入的字符串,并比较两个字符串。