Joke Collection Website - Public benefit messages - Java programming verification code sent to mobile phone

Java programming verification code sent to mobile phone

& lt% @ page content type = " image/JPEG " import = " Java . awt . *,java.awt.image.*,java.util.*,javax.imageio. * " % & gt

& lt%!

Color get randcolor (int fc, int BC){// Get random colors in a given range.

Random Random = new Random();

if(fc & gt; 255)fc = 255;

if(BC & gt; 255)BC = 255;

int r = fc+random . nextint(BC-fc);

int g = fc+random . nextint(BC-fc);

int b = fc+random . nextint(BC-fc);

Returns a new color (r, g, b);

}

% & gt

& lt%

//Set the page not to be cached.

Response.setHeader("Pragma ","no cache ");

response . set header(" Cache-Control "," no-Cache ");

response . setdate header(" Expires ",0);

//Create an image in memory

int width=60,height = 20

BufferedImage image = new buffered image (width, height, buffered image. TYPE _ INT _ RGB);

//Get the graphic context

graphics g = image . get graphics();

//Generate a random class

Random Random = new Random();

//Set the background color

g.setColor(getRandColor(200,250));

g.fillRect(0,0,width,height);

//Set the font

G.setFont ("Times New Roman", font. Plain,18));

//Draw a border

//g . set Color(new Color());

//g.drawRect(0,0,width- 1,height- 1);

// 155 interference lines are randomly generated, which makes the authentication code in the image difficult to be detected by other programs.

g . set color(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);

}

//Take the randomly generated authentication code (4 digits)

//String rand = request . getparameter(" rand ");

//rand = rand.substring(0,rand.indexOf(" . "));

String sRand =

for(int I = 0; I<4; i++){

string rand = string . value of(random . nextint( 10));

sRand+= rand;

//Display the verification code in the image.

g . set Color(new Color(20+random . nextint( 1 10),20+random . nextint( 1 10),20+random . nextint( 1 10))); //The calling functions are all the same color, probably because the seeds are too close, so they can only be generated directly.

G. rope drawing (rand, 13*i+6,16);

}

//Store the authentication code in the session.

session.setAttribute("ccode ",sRand);

//Image takes effect

g . dispose();

//Output the image to the page

ImageIO.write(image," JPEG ",response . get output stream());

% & gt