Primary school period. . Of a new day

Today, task completion:

Today, the basic completion of the framework is filled, back-end systems of the project because of the time, we chose to stand on the shoulders of giants, and find a more suitable modifications in csdn, with our own system adaptation, we have many projects information is written in the database, modify it may be more trouble. Today, the most successful may be increased by a randomized algorithm verification code, as follows:

<%@ page contentType="image/jpeg" %>
<%@ page import="java.awt.*,java.awt.image.*" %>
<%@ page import="java.util.*,javax.imageio.*" %>

<%!
//产生随机颜色函数getRandColor
Color getRandColor(int fc,int bc){
Random r = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int red=fc+r.nextInt(bc-fc); //红
int green=fc+r.nextInt(bc-fc); //绿
int blue=fc+r.nextInt(bc-fc); //蓝
return new Color(red,green,blue);
}
%>

<%
The try {
// set the page is not cached
response.setHeader ( "Pragma", "No-Cache");
response.setHeader ( "the Cache-Control", "Cache-NO");
. Response.setDateHeader ( "the Expires", 0);

// Create stochastic
random r = new random ();

// Create an image in memory, a width of width, height height
int width = 60, height = 20 is;
the BufferedImage new new PIC = the BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);

// Get the graphics context
Graphics gc = pic.getGraphics ();

// set the background color and filled
gc.setColor (getRandColor (200, 250));
gc.fillRect (0, 0, width, height);

// set the graphics context font
gc.setFont (new Font ( "Times New Roman", Font.PLAIN, 18));

@ 200 randomly generated interference straight lines, the authentication code image is difficult to detect other analysis programs
gc.setColor (getRandColor (160,200));
for (int I = 0; I <200 is; I ++) {
int R & lt X1 = .nextInt (width);
int r.nextInt Y1 = (height);
int X2 = r.nextInt (15);
int Y2 = r.nextInt (15);
gc.drawLine (X1, Y1, X1 + X2, Y1 + Y2);
}
// randomly generated interference points 100, the image is difficult to detect other codes analysis program to
gc.setColor (getRandColor (120,240));
for (int I = 0; I <100; I ++)
{
r.nextInt X = int (width);
int Y = r.nextInt (height);
gc.drawOval (X, Y, 0,0);
}

// 4-digit randomly generated codes
String the RS = "";
String RN = "";
for (int I = 0; I <. 4; I ++) {
// within 10 generates a random number RN
RN = String.valueOf ( r.nextInt (10));
the RS = RN +;
// drawString authentication code function to display the image in
gc.setColor (new Color (20 + r.nextInt (110), 20 + r.nextInt (110), 20 r.nextInt + (110)));
gc.drawString (RN, I 13 is * + 6,16);
}

// release the graphics context
gc.dispose ();

// RS code stored in the authentication shared SESSION
session.setAttribute ( "random", RS) ;

// the codes generated output image to the page
ImageIO.write (pic, "JPEG", response.getOutputStream ());

out.clear();
out = pageContext.pushBody();
}
catch(IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}%>

Tomorrow's plan:

Integration, upload the code, ready to reply in the afternoon, do a final conclusion.

Daily Summary:

To be honest, I really do not know to write something very curious about one-third of every day how to write, nothing to search for the blog of primary school students actually can really see, and found it very interesting.

gitlab upload the code 500 has been an error, was said to be a server problem, which is difficult to do, I hope tomorrow can understand how matter in the end.

Today, rain, yes.

 

Guess you like

Origin www.cnblogs.com/xyz53235/p/11468987.html