内容导航:private Color getRandColor(int fc,private int height = 26,int y = (height),int y = (height)
  • java实现验证码的自动识别
  • 用java写的验证码识别技术原理
  • 验证码是啥发送验证码
  • java怎么实现随机4个带有数字和字母的验证码
  • {image}

    一、java实现验证码的自动识别

    方式比较多,用一个二维数组存放 ,如a[5][5]={{,,,,},{"1212","1233","2323","","郑拆并"}},可以动态的生成一个小于5的数字,直接把生成的数字和下标对应 ,在和后面的的字御戚符串比较喊迹就可以自动验证了

    二 、用java写的验证码识别技术原理

    需要技术原理+要点+源码 如果能给出原理和要点可以采纳 ,能给出源码的更好且如果满意了另外加200分。 希望各位大侠帮忙!!!!

    <%@ page contentType="image/jpeg" import=".,.,.,." %><%!Color getRandColor(int fc,int bc){//给定范围获得随机颜色 Random random = new Random(); if(fc>255) fc=255; if(bc>255) bc=255; int r=fc+(bc-fc); int g=fc+(bc-fc); int b=fc+(bc-fc); return new Color(r,g,b); }%><%//设置页面不缓存("Pragma","No- cache");("Cache-Control","no-cache");ader("Expires", 0);

    // 在内存中创建图象int width=60, height=20;BufferedImage image = new BufferedImage(width, height, _INT_RGB);

    // 获取图形上下文Graphics g = cs();

    //生成随机类Random random = new Random();

    // 设定背景色(getRandColor(200,250));(0, 0, width, height);

    //设定字体(new Font("Times New Roman",,18));

    //画边框//(new Color());//(0,0,width-1,height-1);

    // 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到(getRandColor(160,200));for (int i=0;i<155;i++){ int x = (width); int y = (height); int xl = (12); int yl = (12); (x,y,x+xl,y+yl);}

    // 取随机产生的认证码(4位数字)//String rand = ter("rand");//rand = (0,("."));String sRand="";for (int i=0;i<4;i++){ String rand=((10)); sRand+=rand; // 将认证码显示到图象中 (new Color(20+(110),20+(110),20+(110)));//调用函数出来的颜色相同,可能是因为种子太接近 ,所以只能直接生成 g(rand,13*i+6,16);}

    // 将认证码存入ute("rand",sRand);

    // 图象生效();

    // 输出图象到页面(image, "JPEG", Stream());();out = ();%>

    三、验证码是啥发送验证码

    就是你输入登录名和密码之后下面有一个数字,字母,或者组合的 ,你按这个验证码输入空白处就可以了 。就是你收到的一串数字就是显示的那个数字或者英文是系统发给你的

    四、java怎么实现随机4个带有数字和字母的验证码

    import ;
    import ;
    import ;
    import mage;
    import ;

    import ;
    import etRequest;
    import etResponse;
    import on;

    public class RandomValidateCode {

    public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";//放到session中的key
    private Random random = new Random();
    private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生的字符串

    private int width = 80;//图片宽
    private int height = 26;//图片高
    private int lineSize = 40;//干扰线数量
    private int stringNum = 4;//随机产生字符数量
    /
    获得字体
    /
    private Font getFont(){
    return new Font("Fixedsys",_BASELINE,18);
    }
    /

    获得颜色
    /
    private Color getRandColor(int fc,int bc){
    if(fc > 255)
    fc = 255;
    if(bc > 255)
    bc = 255;
    int r = fc + (bc-fc-16);
    int g = fc + (bc-fc-14);
    int b = fc + (bc-fc-18);
    return new Color(r,g,b);
    }
    /
    生成随机图片
    /
    public void getRandcode(HttpServletRequest request,
    HttpServletResponse response) {
    HttpSession session = n();
    //BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
    BufferedImage image = new BufferedImage(width,height,_INT_BGR);
    Graphics g = cs();//产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
    (0, 0, width, height);
    (new Font("Times New Roman",_BASELINE,18));
    (getRandColor(110, 133));
    //绘制干扰线
    for(int i=0;i<=lineSize;i++){
    drowLine(g);
    }
    //绘制随机字符
    String randomString = "";
    for(int i=1;i<=stringNum;i++){
    randomString=drowString(g,randomString,i);
    }
    ribute(RANDOMCODEKEY);
    ute(RANDOMCODEKEY, randomString);
    (randomString);
    ();
    try {
    (image, "JPEG", Stream());//将内存中的图片通过流动形式输出到客户端
    } catch (Exception e) {
    kTrace();
    }
    }
    /
    绘制字符串
    /
    private String drowString(Graphics g,String randomString,int i){
    (getFont());
    (new Color((101),(111),(121)));
    String rand = (getRandomString((())));
    randomString +=rand;
    ((3), (3));
    g(rand, 13
    i, 16);
    return randomString;
    }
    /
    绘制干扰线
    /
    private void drowLine(Graphics g){
    int x = (width);
    int y = (height);
    int xl = (13);
    int yl = (15);
    (x, y, x+xl, y+yl);
    }
    /

    获取随机的字符
    /
    public String getRandomString(int num){
    return ((num));
    }
    }import ;

    public class test {
    public static void main(string[] args) {
    char c = 'i';
    stringbuffer sb = new stringbuffer();
    for (int i = 0; i < 6; i++) {
    int a = ((new random()).nextint(57));// 产生0~57的随机数
    if (a <= 9) {// 将0~9转为char的0~9
    ((char) (a + 48));
    } else if (a < 33) {// 将10~33转为char的a~z
    if((a + 55) == 79 || (a + 55) == 73){
    ((char) (a + 63));
    }else{
    ((char) (a + 55));
    }
    } else {// 将33~57转为char的a~z
    ((char) (a + 63));
    }
    }
    ("随机生成的6位密码为: " + ());
    }
    }

    本文版权归QU快排Www.seoGurubLog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▲61910465