0% found this document useful (0 votes)
29 views1 page

Captcha Js

Javascript - utilitar captcha

Uploaded by

TiberiuBabet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Captcha Js

Javascript - utilitar captcha

Uploaded by

TiberiuBabet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

var capt_code;

function createCaptcha() {
//clear the contents of captcha div first
//document.getElementById('captcha').innerHTML = "";
var charsArray =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!#$%^&*";
var lengthOtp = 6;
var captcha = [];
for (var i = 0; i < lengthOtp; i++) {
//below code will not allow Repetition of Characters
var index = Math.floor(Math.random() * charsArray.length + 1); //get the next
character from the array
if (captcha.indexOf(charsArray[index]) == -1)
captcha.push(charsArray[index]);
else i--;
};

$('div#capt_div').html('<canvas id="capt_canvas" style="position:relative; top:-


52px; left:0px; pointer-events:none;"></canvas>');
var canv = document.getElementById("capt_canvas");
var ctx = canv.getContext("2d");
ctx.font = "48px Georgia";
ctx.strokeText(captcha.join(""), 25, 88);
//storing captcha so that can validate you can save it somewhere else according
to your specific requirements
capt_code = captcha.join("");
//document.getElementById("captcha").appendChild(canv); // adds the canvas to the
body element
};

var valid_capt = false;


function validateCaptcha() {
event.preventDefault();
debugger
if (document.getElementById("cpatchaTextBox").value == capt_code) {
$('input.capt').css({'color':'green'});
valid_capt = true;
//alert("Valid Captcha")
}else{
//alert("Invalid Captcha. try Again");
createCaptcha();
valid_capt = false;
}
};

You might also like