1let captchaText; 2 3// Function to generate random CAPTCHA string 4function generateCaptcha(length) { 5 const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 6 let captcha = ''; 7 for (let i = 0; i < length; i++) { 8 captcha += characters.charAt(Math.floor(Math.random() * characters.length)); 9 } 10 return captcha; 11} 12 13// Function to display CAPTCHA 14function displayCaptcha() { 15 captchaText = generateCaptcha(6); // Change the length as needed 16 const captchaSpan = document.getElementById('captcha'); 17 captchaSpan.textContent = captchaText; 18} 19 20// Function to refresh CAPTCHA 21function refreshCaptcha() { 22 displayCaptcha(); 23 document.getElementById('captchaInput').value = ''; 24 const msg = document.getElementById('msg'); 25 msg.textContent = ''; 26 document.getElementById('submitBtn').disabled = true; // Disable the submit button again 27} 28 29// Function to validate CAPTCHA 30function validateCaptcha() { 31 const userCaptcha = document.getElementById('captchaInput').value; 32 const msg = document.getElementById('msg'); 33 const submitBtn = document.getElementById('submitBtn'); 34 35 if (userCaptcha === captchaText) { 36 msg.textContent = 'Verified!'; 37 msg.style.color = 'green'; 38 submitBtn.disabled = false; // Enable the submit button 39 } else { 40 msg.textContent = 'Invalid'; 41 msg.style.color = 'red'; 42 submitBtn.disabled = true; // Ensure the submit button is disabled 43 } 44} 45 46// Initial CAPTCHA display 47window.onload = displayCaptcha;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.