hualishu
V2EX  ›  Android

用 JFinal 生成随机验证码

  •  
  •   hualishu · Feb 17, 2016 · 15473 views
    This topic created in 3755 days ago, the information mentioned may be changed or developed.

    这篇文章,介绍利用 JFinal 的 CaptchaRender 生成随机验证码,效果如下:

    Alt text
    验证码区分大小写,输入正确访问博客首页,否则停留在登录页面。
    IndexController.java

    ``package com.demo.index;

    import com.jfinal.core.Controller;
    import com.jfinal.ext.render.CaptchaRender;

    /**
    * IndexController
    */
    public class IndexController extends Controller {
    public void index() {
    render("index.html");
    }

    private static final String RANDOM_CODE_KEY = "1";

    public void login() {
    String inputRandomCode = getPara("inputRandomCode");
    boolean loginSuccess = CaptchaRender.validate(this, inputRandomCode, RANDOM_CODE_KEY);
    if (loginSuccess) {
    redirect("/blog");
    } else {
    index();
    }
    }

    public void img() {
    CaptchaRender img = new CaptchaRender(RANDOM_CODE_KEY);
    render(img);
    }
    }``

    源码下载

    12 replies    2016-02-18 18:18:03 +08:00
    hualishu
        1
    hualishu  
    OP
       Feb 17, 2016
    markdown 插入代码 怎么弄? 问下大家
    icanfork
        2
    icanfork  
       Feb 17, 2016
    你应该尝试发一篇《细谈 Android 架构》我觉得这里的朋友会喜欢更多。
    admol
        3
    admol  
       Feb 17, 2016
    ```
    三个
    ```
    lll000lll
        4
    lll000lll  
       Feb 17, 2016
    hao
    Troevil
        5
    Troevil  
       Feb 17, 2016
    jfinal 的自带的这个验证码好像是 md5 存到 cookies , 理论上无限爆破
    RRL
        6
    RRL  
       Feb 18, 2016
    @Troevil 确实是 cookies 保存
    hualishu
        7
    hualishu  
    OP
       Feb 18, 2016
    @belin520 好的,我想想 该怎么发
    hualishu
        8
    hualishu  
    OP
       Feb 18, 2016
    @admol 我试一下
    ppwangs
        9
    ppwangs  
       Feb 18, 2016
    区分大小写不理性
    hualishu
        10
    hualishu  
    OP
       Feb 18, 2016
    @ppwangs 插入代码还是有问题啊
    raysonx
        11
    raysonx  
       Feb 18, 2016 via iPad
    这验证码。。。几分钟就能写个程序把它识别掉。
    后面的背景噪线特征明显,直接过滤颜色就可滤掉。
    纵向投影分割掉字符后,随便一个分类算法就能识别了。
    建议不要为验证码而验证码。
    Troevil
        12
    Troevil  
       Feb 18, 2016
    @raysonx ... 验证码用的 cookies 验证的. 直接保存 cookies 上面 的 那串 md5 就 OK , 上验证码识别就是用了牛刀了, 这个功能可能也是给出官方给出的一个例子吧, 可用性不强
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1418 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 16:52 · PVG 00:52 · LAX 09:52 · JFK 12:52
    ♥ Do have faith in what you're doing.