kaptcha配置属性

ConstantDescriptionDefault
kaptcha.borderBorder around kaptcha. Legal values are yes or no.(设置是否有边框 yes
kaptcha.border.colorColor of the border. Legal values are r,g,b (and optional alpha) or white,black,blue.(设置边框颜色

black

(105,179,90)

kaptcha.border.thicknessThickness of the border around kaptcha. Legal values are > 0.1
kaptcha.image.widthWidth in pixels of the kaptcha image.(设置验证码宽度200
kaptcha.image.heightHeight in pixels of the kaptcha image.(设置验证码高度50
kaptcha.producer.implThe image producer.com.google.code.kaptcha.impl.DefaultKaptcha
kaptcha.textproducer.implThe text producer.

获取中文

com.google.code.kaptcha.text.impl.DefaultTextCreator

(org.cric.util.ChineseText)

kaptcha.textproducer.char.stringThe characters that will create the kaptcha.abcde2345678gfynmnpwx
kaptcha.textproducer.char.lengthThe number of characters to display.(设置字体个数5
kaptcha.textproducer.font.namesA list of comma separated font names.(设置字体样式Arial, Courier(宋体,楷体,微软雅黑)
kaptcha.textproducer.font.sizeThe size of the font to use.( 设置字体大小40px.
kaptcha.textproducer.font.colorThe color to use for the font. Legal values are r,g,b.(设置字体颜色black
kaptcha.noise.implThe noise producer.com.google.code.kaptcha.impl.DefaultNoise
kaptcha.noise.colorThe noise color. Legal values are r,g,b.black
kaptcha.obscurificator.implThe obscurificator implementation.com.google.code.kaptcha.impl.WaterRipple
kaptcha.background.implThe background implementation.com.google.code.kaptcha.impl.DefaultBackground
kaptcha.background.clear.fromStarting background color. Legal values are r,g,b.light grey
kaptcha.background.clear.toEnding background color. Legal values are r,g,b.white
kaptcha.word.implThe word renderer implementation.com.google.code.kaptcha.text.impl.DefaultWordRenderer
kaptcha.session.keyThe value for the kaptcha is generated and is put into the HttpSession. This is the key value for that item in the session.KAPTCHA_SESSION_KEY
kaptcha.session.dateThe date the kaptcha is generated is put into the HttpSession. This is the key value for that item in the session.KAPTCHA_SESSION_DATE
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kaptcha是一个Google开源的图片验证码生成工具,可以根据属性来设置自己想要的基本意义上的验证码。在前端中,可以通过获取验证码图片对用户输入的验证码进行简单的规则校验返回登录结果,并提供刷新验证码的动作,防止出现用户难以辨识的识别码。在SpringBoot中,可以通过导入依赖和配置KaptchaConfig来集成创建验证码工具。具体步骤如下: 1. 导入POM依赖:在pom.xml文件中添加以下依赖: <dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha</artifactId> <version>2.3.2</version> </dependency> 2. 配置KaptchaConfig:在配置类中添加以下代码: @Bean public DefaultKaptcha producer() { Properties properties = new Properties(); // 设置验证码图片的宽度 properties.setProperty("kaptcha.image.width", "150"); // 设置验证码图片的高度 properties.setProperty("kaptcha.image.height", "50"); // 设置验证码字符的长度 properties.setProperty("kaptcha.textproducer.char.length", "4"); // 设置验证码字符的范围 properties.setProperty("kaptcha.textproducer.char.string", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // 设置验证码字体的大小 properties.setProperty("kaptcha.textproducer.font.size", "30"); // 设置验证码字体的颜色 properties.setProperty("kaptcha.textproducer.font.color", "black"); // 设置验证码噪点的颜色 properties.setProperty("kaptcha.noise.color", "black"); // 设置验证码噪点的生成方式 properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise"); // 设置验证码样式 properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy"); Config config = new Config(properties); DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); defaultKaptcha.setConfig(config); return defaultKaptcha; } 3. 在前端页面中添加验证码输入框和图片:在验证码输入框后面添加以下代码: <span> <input type="text" id="code" name="tryCode" placeholder="VerfiCode">  <img alt="验证码" onclick="this.src='/kaptcha?d='+new Date()*1" th:src="@{./kaptcha}"/> </span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值