Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security » 精华区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请问一下DEV-Club.COM上的彩色校验码怎么做的.
momocha





发贴: 98
积分: 10
于 2004-01-29 18:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
本论坛也有,有没有大哥有源码共享一下..谢谢了!!!


作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:momocha]
menzy



版主


发贴: 754
积分: 113
于 2004-01-29 19:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
BufferedImage image = new BufferedImage(60, 20,
BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

// 设定背景色
g.setColor(Color.white);
g.fillRect(0, 0, width, height);

//画边框
g.setColor(Color.black);
g.drawRect(0,0,width-1,height-1);

// 取随机产生的认证码(4位数字)
String rand = request.getParameter("rand");
rand = rand.substring(0,rand.indexOf("."));
switch(rand.length())
{
  case 1: rand = "000"+rand; break;
  case 2: rand = "00"+rand; break;
  case 3: rand = "0"+rand; break;
  default: rand = rand.substring(0,4); break;
}

// 将认证码存入SESSION。。。。

// 将认证码显示到图象中
g.setColor(Color.black);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.drawString(rand,10,15);

// 随机产生干扰点
Random random = new Random();
for (int i=0;i<88;i++)
{
  int x = random.nextInt(width);
  int y = random.nextInt(height);
  g.drawLine(x,y,x,y);
}

// 图象生效
g.dispose();

// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());

=======================================
调用的时候用脚本写
document.write("<img border=0 src=image.jsp?
rand="+Math.random()*10000+">");


floater edited on 2004-01-29 23:03

作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:momocha]
menzy



版主


发贴: 754
积分: 113
于 2004-01-29 19:23 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
至于图像的颜色,你自己搞定


作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:menzy]
helloworld



发贴: 0
积分: 0
于 2004-01-29 21:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我想是分开校验,数字在先,密码在后.

可以防止暴力破解用户密码.


helloworld edited on 2004-02-04 08:04


作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:momocha]
momocha





发贴: 98
积分: 10
于 2004-02-02 09:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢!生成图片我已明白,,我想问问关于校验的问题:
1.生成图片校验有什么好处,用随机数直接输出也可以呀
2.我的思路是这样,不知正确否.用随机数生成图片,然后把随机数保存在session中,然后得到输入表单提交的数据跟session中进行比较,是这样吗?想问一下用户名密码校验跟数字校验是分开校验还是合起来.



作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:momocha]
menzy



版主


发贴: 754
积分: 113
于 2004-02-04 08:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好处是增加保密性,不太可能永嗅探器发现form中直接发送给客户端的信息


作者 Re:请问一下DEV-Club.COM上的彩色校验码怎么做的. [Re:momocha]
Wendy0007





发贴: 120
积分: 0
于 2004-03-15 15:42 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
明白^_^

谢谢!!




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923