The main content of this article is: Use Java text box to make verification code .
Design ideas:
1. When the page loads, the verification code is generated automatically.
2, after JS to determine whether the verification code is entered correctly
Advantages:
The code is simple and easy to use. The correctness of the verification code can be determined directly in the page without uploading to the background action.
Disadvantages:
Since this verification code is made of text, it is easy to be crawled by the browser/manual copy, losing its essential features (security).
<script type= "Text/javascript" >var code; In the global definition of the CAPTCHA function Createcode () { code = ""; var codelength = 4;//The length of the verification code var Checkcode = document.getElementById (" Checkcode ") var Selectchar = new Array (0,1,2,3,4,5,6,7,8,9, ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' J ', ' K ', ' L ', ' M ', ' N ', ' P ') , ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ');//All the candidates that make up the verification code, of course, can also be used in Chinese for (Var i=0;i<codelength;i++) { var CharIndex = Math.floor (Math.random () *34); code +=selectchar[charindex]; } if (checkcode) {checkcode.classname= "code"; checkcode.value = Code;} document.getElementById ("code"). focus (); function Check () { if (document.getElementById ("code"). Value.replace (/\\s/g, ')! = code) {alert ("CAPTCHA input Error! Createcode ();//Refresh Authenticode document.getElementById ("code"). focus (); return false;} } </script>
</pre><pre code_snippet_id= "501094" snippet_file_name= "blog_20141029_2_4692873" name= "code" class= "HTML" ><body onload= "Javascript:createcode (); ><s:form action= "User_login" onsubmit= "return check ()" ><input type= "text" id= "code" class= "DZ" style = "width:110px;"/><input type= "text" onclick= "Createcode ()" readonly= "readonly" id= "Checkcode" class= "code" Title= "for a" style= "WIDTH:68PX; height:27px; Cursor:not-allowed "/></s:form></body>
Work Note 5. Java text Box Verification code