-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (39 loc) · 1.43 KB
/
script.js
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
(function(){
const fonts = ["cursive", "sans-serif", "serif", "monospace"];
let captchaValue = "";
function generateCaptcha(){
let value = btoa(Math.random()*1000000000);
value = value.substr(0,5+Math.random()*5);
captchaValue = value;
}
function setCaptcha(){
let html = captchaValue.split("").map((char) =>{
const rotate = -20 + Math.trunc(Math.random()*30);
const font = Math.trunc(Math.random()*fonts.length);
return `<span
style="
transform: rotate(${rotate}deg);
font-family: ${fonts[font]}
"
>${char}</span>`;
}).join("");
document.querySelector(".login-form .captcha .preview").innerHTML = html;
}
function initCaptcha(){
document.querySelector(".login-form .captcha .captcha-refresh").addEventListener("click", function(){
generateCaptcha();
setCaptcha();
});
generateCaptcha();
setCaptcha();
}
initCaptcha();
document.querySelector(".login-form #login-btn").addEventListener("click", function(){
let inputCaptchaValue = document.querySelector(".login-form .captcha input").value;
if(inputCaptchaValue === captchaValue){
swal("", "Login Successfull", "success");
} else{
swal("", "Invalid Captcha!", "warning");
}
});
})();