Verification code

Please give some method to produce Daniel landing is code and code

Started by Winnie at November 09, 2016 - 11:20 PM

His Baidu Google does not have.

Posted by Julia at November 18, 2016 - 11:21 PM

It's Fairy simple. Let me show you: <%@ page
import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"%>

<%@ page import="java.io.OutputStream"%>
<%@ page pageEncoding="UTF-8"%>
<%!Color getRandColor(int fc, int bc) {
//Given the range of random color
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);
}%>

<%
try {
//Set the page not cached
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
// Create the image in the memory
int width = 60, height = 20;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
//The current output is returned to the client
OutputStream os = response.getOutputStream();
// Gets the graphics context
Graphics g = image.getGraphics();
//The generation of random objects
Random random = new Random();
// Set 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));
//Randomly generated 155 interference lines
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);
}
//Randomly generated Aa-Zz 0-9 4 bit code!
String sRand = "";
char[] str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
.toCharArray();
for (int i = 0; i <4; i++) {

String rand = String.valueOf(str[random.nextInt(36)]);
sRand += rand;
// The authentication code is displayed in the image
g.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 13 * i + 6, 16);
}

// The authentication code is in SESSION
session.setAttribute("rand", sRand);
// Image effect
g.dispose();

//The output image to the page!
ImageIO.write(image, "JPEG", os);
os.flush();
os.close();
os = null;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
} catch (IllegalStateException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
%>

Posted by Jill at November 30, 2016 - 11:34 PM

The best followed by time stamp , (new Date()).getTime();

Posted by Angelo at December 05, 2016 - 11:57 PM

There are many online, you have to search.

Posted by Abby at December 13, 2016 - 12:42 AM