Skip to content Skip to sidebar Skip to footer

Captcha Validation With Javascript

I am trying to validate Captcha using JavaScript. But I could't find any resource about Client API's of Captcha. Do you have any documentation?

Solution 1:

If you could validate the captcha through JavaScript that would mean the means of finding out the valid code would be readily available in the code that you're passing to the client, which would effectively invalidate the use for a captcha altogether.

The only secure way to achieve this would be to send an AJAX request to the server, which would then validate the code. This way, your validation would be done exactly the way you normally validate the captcha on the server.

Solution 2:

Validating a captcha with javascript would mean that you would need to have some representation of your captcha text visible in your html source, which is automatically visible to a bot.

I think a possibility if you absolutely have to validate using javascript would be to hash your captcha text server side, load it in a javascript variable, and then validate using the equivalent javascript hashing function.

Solution 3:

It would be a bad idea to validate the CAPTCHA using JavaScript as a robot could easily beat the CAPTCHA then. If you mean you want to make an Ajax call to submit the entered text that is slightly different.

Solution 4:

You can use this it works and is very simple

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 
 */functionmyFunction() {
    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
 */functionchaeckCpatch(id)
{
		if($("#"+id).val()==val[x])
		{
				alert("match");
		}
		else
		{
			alert("No match");
		}
	
}
<!DOCTYPE htmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head></head><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script><body><!--  below div use to display captcha image --><divid="imgCaptchaPlace"></div><!-- below textfield where user enter captcha value --><inputtype="text"id="captchaText"onchange="chaeckCpatch(this.id);"/><!-- include this JS file --><scriptsrc="captchByAarif.js"type="text/javascript"></script></body></html>

You can download captcha images that are used in this example here

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

Solution 5:

Just as a proof of concept... If you send a HASH of captcha string to browser. You could than dynamically HASH the string entered by the user, and compare the two strings.

Post a Comment for "Captcha Validation With Javascript"