用java生成一个附加码。
来源:互联网 发布:简单重复的工作 知乎 编辑:程序博客网 时间:2024/04/27 14:44
好久没有写个东西了.最近好忙.希望大家能够用的上这个附加码.
/**
*@作者 pxjianke
*@目标 生成附加码,免得别人破解密码
*
*/
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import java.awt.Color;
import com.encrypts.StringEncrypt;
public class AuthImgServlet
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
private static char numbersAndLetters[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
private Font mFont = new Font("Times New Roman", Font.BOLD, 14);
public AuthImgServlet() {
}
//Initialize global variables
public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("image/jpeg");
ServletOutputStream out = response.getOutputStream();
BufferedImage image = new BufferedImage(70, 17, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, 70, 17);
g.setColor(Color.red);
g.setFont(mFont);
String temp=getStringCode(6);
HttpSession hs=request.getSession();
hs.setAttribute("createImage",(new StringEncrypt(temp.toLowerCase())).toString());
for(int i=0;i<6;i++){
g.drawString(temp.substring(i,i+1),i*11+2,14);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
private String getStringCode(int len) {
StringBuffer strCode = new StringBuffer();
int nRand = (int) Math.round(Math.random() * 100D);
for (int i = 0; i < len; i++) {
nRand = (int) Math.round(Math.random() * 100D);
strCode.append(numbersAndLetters[nRand % (numbersAndLetters.length - 1)]);
}
return strCode.toString();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
- 用java生成一个附加码。
- 用java生成附加码
- servlet 生成 附加码 (转载)
- JAVA:附加码生成器(图片)
- JAVA:附加码生成器(图片)
- GIF动画附加码的例子JAVA版本
- 附加码生产程序
- 附加码自动识别
- 附加码看不见的解决方法
- java MD5加码
- 论附加码在网络安全中的作用
- GIF动画附加码的例子
- java-Base64加码解码类
- MD5加码 生成32位md5码
- 网页的验证码(附加码)的产生(源代码)。
- 论使用附加码方法在网络安全中的作用
- 全面认识网页中附加码的作用
- 全面认识网页中附加码的作用
- SQL Server补丁版本的检查
- 对预编译头文件的理解
- 今天吃饱了撑着的重要决定
- Session丢失原因
- 求Struts中html:select从Sql Server数据库动态加载数据
- 用java生成一个附加码。
- ASP.NET配置文件Web.config
- Global.asax以及Web应用的生命周期
- oracle数据安全面面观
- XML 问题: 超越 DOM
- 如何读取保存在数据库中的图片显示在DataGrid中
- SegWord::IHash
- 《多挣了三五千》
- Understand memory access characteristics of motion estimation algorithms