Implementation and technical analysis of verification codes generated by js, and technical analysis of js verification Codes

Source: Internet
Author: User

Implementation and technical analysis of verification codes generated by js, and technical analysis of js verification Codes

I will share with you a piece of code for generating and verifying the verification code in js.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

As we all know, JavaScript is a client, is it meaningful to make all the verification on the client? Is the verification code generated from the server safe? Is the verification code generated by the front-end secure?

The verification code is dynamic, but it must be identified by the client and the correct value should be returned for normal verification. This is a process problem. if Javascript is used, it is verified on the client. It is basically the same !!! It is best to generate a server, verify the client, confirm the server, and browse normally. Such a process is foolproof.

Therefore, this article is only a technical discussion. Never use it in actual production projects.


How to Use JS to implement login verification code

<% @ Page contentType = "image/jpeg" import = "java. awt .*,
Java. awt. image. *, java. util. *, javax. imageio. * "pageEncoding =" GBK "%>
<%!
Color getRandColor (int fc, int bc) {// obtain a random Color from a given range
Random random = new Random ();
If (fc> 255) fc = 255;
If (bc> 255) bc = 255;
Int r = fc + random. nextInt (bc-fc );
Int g = fc + random. nextInt (bc-fc );
Int B = fc + random. nextInt (bc-fc );
Return new Color (r, g, B );
}
%>
<%
// Set the page not to cache
Response. setHeader ("Pragma", "No-cache ");
Response. setHeader ("Cache-Control", "no-cache ");
Response. setDateHeader ("Expires", 0); // create an image in the memory
Int width = 60, height = 20;
BufferedImage image = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB); // obtain the image Context
Graphics g = image. getGraphics (); // generates a random class
Random random = new Random (); // sets the background color.
G. setColor (getRandColor (200,250 ));
G. fillRect (0, 0, width, height); // set the font
G. setFont (new Font ("Times New Roman", Font. PLAIN, 18); // draw a border
// G. setColor (new Color ());
// G. drawRect (155, width-1, height-1); // interference lines are randomly generated, making the authentication code in the image hard to be detected by other programs.
G. setColor (getRandColor (160,200 ));
For (int I = 0; I <155; I ++)
{
Int x = random. nextInt (width );
Int y = random. nextInt (height );
Int xl = random. nextInt (12 );
Int yl = random. nextInt (12 );
G. drawLine (x, y, x + xl, y + yl );
} // Obtain the random ID (4 digits)
String sRand = "";
For ...... the remaining full text>
 
How can I use javascript to generate a verification code? Do you know?

Js is easy to crack and is not recommended for use.

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.