Work Note 5. Java text Box Verification code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.