-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptchaJS.js
More file actions
63 lines (61 loc) · 1.63 KB
/
Copy pathcaptchaJS.js
File metadata and controls
63 lines (61 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Author: Achraf Almouloudi
Project: CaptchaJS
Version: 1.2
*/
// Settings variables
var formID = 'formID';
var cookieName = 'captchaCookie';
var inputName = 'captchaInput';
// Read cookie function //
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); }
}
}
// Invisible Form Captcha //
if (readCookie(cookieName) == null)
{
// Set function parameters
var chars = "abcdefghiklmnopqrstuvwxyz0123456789";
var string_length = 32;
var randomString = '';
// Generate a string
for (var i=0; i<string_length; i++)
{
var rnum = Math.floor(Math.random() * chars.length);
randomString += chars.substring(rnum,rnum+1);
}
// Create captcha cookie
document.cookie=cookieName+"="+randomString+";expires=0;path=/";
}
// Select the form submit button
var inputs = document.getElementById(formID).getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++)
{
if(inputs[i].type.toLowerCase() == 'submit')
{
var submitButton = inputs[i];
}
}
// Output the value of the cookie into the hidden captcha input
if (submitButton != null)
{
submitButton.onclick = function()
{
// Create input element
var element = document.createElement('input');
element.name = inputName;
element.type = 'text';
element.style = 'display: none';
element.value = readCookie(cookieName);
// Injecvt captcha input
submitButton.parentNode.insertBefore(element, submitButton);
}
}