`
jslfl
  • 浏览: 318856 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Kaptcha验证码配置项

阅读更多
导包

web.xml:
<servlet>
        <servlet-name>Kaptcha</servlet-name>
        <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
        <init-param>
            <description> Border around kaptcha. Legal values are yes or no. </description>
            <param-name>kaptcha.border</param-name>
            <param-value>no</param-value>
        </init-param>
        <init-param>
            <description>Color of the border. Legal values are r,g,b (and optional alpha) or white,black,blue. </description>
            <param-name>kaptcha.border.color</param-name>
            <param-value>red</param-value>
        </init-param>
        <init-param>
            <description>Thickness of the border around kaptcha. Legal values are > 0. </description>
            <param-name>kaptcha.border.thickness</param-name>
            <param-value>5</param-value>
        </init-param>
        <init-param>
            <description>Width in pixels of the kaptcha image. </description>
            <param-name>kaptcha.image.width</param-name>
            <param-value>80</param-value>
        </init-param>
        <init-param>
            <description>Height in pixels of the kaptcha image. </description>
            <param-name>kaptcha.image.height</param-name>
            <param-value>40</param-value>
        </init-param>
        <init-param>
            <description>The image producer. </description>
            <param-name>kaptcha.producer.impl</param-name>
            <param-value>com.google.code.kaptcha.impl.DefaultKaptcha </param-value>
        </init-param>
        <init-param>
            <description>The text producer. </description>
            <param-name>kaptcha.textproducer.impl</param-name>
            <param-value>com.google.code.kaptcha.text.impl.DefaultTextCreator</param-value>
        </init-param>
        <init-param>
            <description>The characters that will create the kaptcha. </description>
            <param-name>kaptcha.textproducer.char.string</param-name>
            <param-value>abcde2345678gfynmnpwx </param-value>
        </init-param>
        <init-param>
            <description>The number of characters to display. </description>
            <param-name>kaptcha.textproducer.char.length</param-name>
            <param-value>5</param-value>
        </init-param>
        <init-param>
            <description>A list of comma separated font names.</description>
            <param-name>kaptcha.textproducer.font.names</param-name>
            <param-value>Arial, Courier</param-value>
        </init-param>
        <init-param>
            <description>The size of the font to use. </description>
            <param-name>kaptcha.textproducer.font.size</param-name>
            <param-value>23</param-value>
        </init-param>
        <init-param>
            <description>The color to use for the font. Legal values are r,g,b. </description>
            <param-name>kaptcha.textproducer.font.color</param-name>
            <param-value>black</param-value>
        </init-param>
        <init-param>
            <description>The noise producer. </description>
            <param-name>kaptcha.noise.impl</param-name>
            <param-value>com.google.code.kaptcha.impl.NoNoise </param-value>
        </init-param>
        <init-param>
            <description>The noise color. Legal values are r,g,b. </description>
            <param-name>kaptcha.noise.color</param-name>
            <param-value>black</param-value>
        </init-param>
        <init-param>
            <description>The obscurificator implementation. </description>
            <param-name>kaptcha.obscurificator.impl</param-name>
            <param-value>com.google.code.kaptcha.impl.ShadowGimpy</param-value>
        </init-param>
        <init-param>
            <description>The background implementation. </description>
            <param-name>kaptcha.background.impl</param-name>
            <param-value>com.google.code.kaptcha.impl.DefaultBackground</param-value>
        </init-param>
        <init-param>
            <description>Ending background color. Legal values are r,g,b. </description>
            <param-name>kaptcha.background.clear.to</param-name>
            <param-value>white</param-value>
        </init-param>
        <init-param>
            <description>The word renderer implementation. </description>
            <param-name>kaptcha.word.impl</param-name>
            <param-value>com.google.code.kaptcha.text.impl.DefaultWordRenderer</param-value>
        </init-param>
        <init-param>
            <description>The value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session. </description>
            <param-name>kaptcha.session.key</param-name>
            <param-value>KAPTCHA_SESSION_KEY</param-value>
        </init-param>
        <init-param>
            <description>The date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session. </description>
            <param-name>kaptcha.session.date</param-name>
            <param-value>KAPTCHA_SESSION_DATE</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Kaptcha</servlet-name>
        <url-pattern>/Kaptcha.jpg</url-pattern>
    </servlet-mapping>



jsp:
<img id="kaptchaImg" src="<%=path%>/kaptcha.jpg" title="看不清,点击换一张"
onclick="updateImg(this)" style="cursor: pointer;float:left;" />

function updateImg(obj) {
obj.src = "<%=path%>/kaptcha.jpg?" + Math.floor(Math.random() * 100);
}

java:
String kaptchaExpected = (String)request.getSession()
.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);


if (yzm == null || !yzm.equalsIgnoreCase(kaptchaExpected))
{
request.setAttribute("err", "验证码错误!");
request.setAttribute("yh", yh);
return new JspView("/admin/login.jsp");
}
分享到:
评论

相关推荐

    kaptcha验证码配置的三种方式(总结在一个演示项目中)

    以上就是Kaptcha验证码配置的三种方式。在实际项目中,你可以根据需求选择适合的配置方式。无论哪种方式,最终目的都是为了生成安全且易于识别的验证码,保护系统免受自动化攻击。在项目中,可以参照提供的`kaptcha1...

    spring整合kaptcha验证码的实现

    首先,kaptcha是一个很有用的验证码生成工具,由于它有许多可配置项,所以用它可以简单快捷的生成各式各样的验证码。kaptcha的主要特点是可以生成图片验证码、音频验证码、数学验证码等多种类型的验证码,同时也支持...

    kaptcha验证码

    《kaptcha验证码:Java平台上的高效解决方案》 验证码(CAPTCHA)作为一种防止自动化程序自动提交表单的安全机制,被广泛应用于网站登录、注册、评论等场景。在Java开发环境中,kaptcha是一个备受青睐的第三方插件...

    idea+maven+kaptcha验证码实现

    // 配置项,如干扰线数量、文本字体、背景颜色等 props.put("kaptcha.textproducer.char.length", "4"); props.put("kaptcha.textproducer.font.names", "宋体,黑体"); props.put("kaptcha.obscurificator.impl...

    kaptcha 图片验证码

    -- 其他配置项... --&gt; ``` 3. 创建Controller:创建一个控制器类,提供一个接口用于生成验证码图片,该接口返回类型通常为“image/jpeg”。 ```java @Controller public class CaptchaController { @...

    kaptcha验证码使用

    ### Kaptcha验证码使用详解 #### 一、Kaptcha简介 Kaptcha是一款强大的验证码生成工具,由Java编写而成,被广泛应用于Web应用中。其最大的特点在于高度可定制性,允许开发者根据需求调整验证码的样式与内容。这...

    springboot整合kaptcha验证码的示例代码

    在 Spring Boot 中整合 Kaptcha 验证码可以通过两种方式实现:方式一是通过 kaptcha.xml 配置文件,方式二是通过 Java 配置类。 方式一:通过 kaptcha.xml 配置文件 首先,需要在 pom.xml 文件中添加 Kaptcha 的...

    kaptcha验证码使用方法详解

    kaptcha验证码使用方法详解 kaptcha验证码是一种常用的验证码生成工具,...kaptcha验证码使用方法非常简单,只需要在pom.xml文件中添加依赖项,在web.xml文件中配置servlet,在页面中添加验证码的显示和输入框即可。

    kaptcha验证码组件使用简介解析

    kaptcha验证码组件使用简介解析 Kaptcha验证码组件是基于SimpleCaptcha的开源项目,提供了强大的验证码生成和验证功能。该组件的使用非常方便,只需添加jar包依赖和简单的配置就可以使用了。 一、添加jar包依赖 ...

    spring mvc 使用kaptcha配置生成验证码实例

    这里的配置项允许我们定制验证码的外观,例如边框、颜色、大小等。`kaptcha.session.key`的值是生成的验证码在会话(session)中存储的键名。 接下来,我们需要创建一个Spring MVC的Controller类,以处理生成验证码...

    Spring MVC中使用Google kaptcha验证码的方法详解

    在Spring MVC中集成Google kaptcha验证码能够有效地防止恶意登录和批量操作。kaptcha是一个高度可配置的验证码生成库,能够创建各种样式的验证码。以下是如何在Spring MVC项目中使用kaptcha的详细步骤: 1. **Maven...

    kaptcha demo 简单的验证码工具

    7. **定制化**:Kaptcha 提供了丰富的配置选项,可以根据实际需求进行调整,例如改变验证码的长度、字体样式、背景图像等,以提高用户体验并保持验证码的安全性。 通过 kaptcha_demo,开发者可以快速了解和掌握 ...

    Spring boot如何集成kaptcha并生成验证码

    Spring Boot 集成 Kaptcha 生成验证码 Spring Boot 是一个基于 Java 语言的框架,它提供了很多实用的功能来帮助开发者快速构建应用程序。...Kaptcha 提供了许多有用的功能和配置项,可以满足不同的验证码生成需求。

    kaptcha是google开源的一个非常实用的验证码生成工具类,里面包含kaptcha jar包和打包命令

    配置项包括但不限于: 1. 验证码文本长度:可以通过`kaptcha.textproducer.char.length`设置。 2. 字体:可以指定`kaptcha.textproducer.font.names`来改变字体。 3. 字体颜色:`kaptcha.textproducer.char.color`...

    SpringMvc使用GoogleKaptcha生成验证码

    SpringMvc项目中使用GoogleKaptcha生成验证码是一项常见的安全措施,用于防止自动化程序(如机器人)对网站进行恶意操作。Google Kaptcha是一个强大的验证码生成库,它允许开发者自定义生成的验证码的样式和特性。在...

    spring-gateway实现登录验证码校验的代码,百分百可用

    Kaptcha 是一个 Java 实现的验证码生成器,它可以生成包含字母和数字的复杂图片,并具有可配置的样式和扭曲程度,从而增加破解的难度。 首先,我们需要在项目中引入 Kaptcha 的依赖。在 Maven 或 Gradle 的配置文件...

    java实现多种验证码

    记住,为了提高安全性,应定期更换验证码配置,避免被破解。同时,前端验证时,除了比较输入的验证码文本外,还应该检查用户提交答案的正确性(对于算式验证码)。这样,你的系统就能有效地防止自动化攻击,保护用户...

Global site tag (gtag.js) - Google Analytics