Generating Authenticode Java verification Code via response

Source: Internet
Author: User
generating Authenticode via response
Verification Code:
Role: Preventing violent attacks
Click to change the JS code:
function changeimg (obj) {
Operation SRC Attribute
Obj.src= "/test/code?i=" +math.random ();

}


Code reference:

public class Codeservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse respons
		E) throws Servletexception, IOException {//Using Java Graphical interface technology to draw a picture int charNum = 4;
		int width = 30 * 4;

		int height = 30; 1.

		Create a picture of memory bufferedimage bufferedimage = new BufferedImage (width, height, bufferedimage.type_int_rgb);

		2. Get the drawing object Graphics Graphics = Bufferedimage.getgraphics ();
		3, draw the background color graphics.setcolor (color.yellow);

		Graphics.fillrect (0, 0, width, height);
		4, draw the picture border Graphics.setcolor (Color.Blue);

		Graphics.drawrect (0, 0, width-1, height-1);
		5, output verification code content Graphics.setcolor (color.red);

		Graphics.setfont (New Font ("Song Body", Font.Bold, 20));
		Randomly output 4 characters graphics2d graphics2d = (graphics2d) graphics;
		String s = "ABCDEFGHGKLMNPQRSTUVWXYZ23456789";
		Random Random = new Random ();
		String msg = "" is used in the session;
		int x = 5;
			for (int i = 0; i < 4; i++) {int index = Random.nextint (32); String content = String.valueof (S.charat (index));
			msg + content;
			Double theta = Random.nextint (a) * math.pi/180;
			Let the font twist graphics2d.rotate (theta, X, 18);
			Graphics2d.drawstring (content, X, 18);
			Graphics2d.rotate (-theta, X, 18);
		x + 30;
		}//6, Draw interference line Graphics.setcolor (Color.gray);
			for (int i = 0; i < 5; i++) {int x1 = random.nextint (width);

			int x2 = random.nextint (width);
			int y1 = random.nextint (height);
			int y2 = random.nextint (height);
		Graphics.drawline (x1, y1, x2, y2);

		}//release of resources graphics.dispose ();

	Picture Output ImageIO imageio.write (bufferedimage, "JPG", Response.getoutputstream ());

	public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
 }

}


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.