springboot 整合 谷歌 Captcha验证码
1.pom依赖
<!-- 谷歌 Captcha验证码依赖 --><dependency><groupId>com.github.axet</groupId><artifactId>kaptcha</artifactId><version>0.0.9</version></dependency>
2.新建CaptchaConfig.java文件
/*** 谷歌 Captcha验证码配置类*/
@Configuration
public class CaptchaConfig {@Beanpublic DefaultKaptcha defaultKaptcha() {// 验证码生成器DefaultKaptcha defaultKaptcha = new DefaultKaptcha();// 配置Properties properties = new Properties();// 是否有边框properties.setProperty("kaptcha.border","yes");// 设置边框颜色properties.setProperty("kaptcha.border.color","105,179,90");// 验证码properties.setProperty("kaptcha.session.code","code");// 验证码文本字符颜色,默认为黑色properties.setProperty("kaptcha.textproducer.font.color","blue");// 设置字体样式properties.setProperty("kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");// 字体大小,默认为40properties.setProperty("kaptcha.textproducer.font.size","30");// 字符长度,默认为5properties.setProperty("kaptcha.textproducer.char.length","4");// 字符间距,默认为2properties.setProperty("kaptcha.textproducer.char.space","4");// 验证码图片宽度,默认为200properties.setProperty("kaptcha.iamge.width","100");// 验证码图片高度,默认为40properties.setProperty("kaptcha.iamge.height", "40");Config config = new Config(properties);defaultKaptcha.setConfig(config);return defaultKaptcha;}
}
3.新建CaptchaController接口
/*** 谷歌 Captcha验证码 接口*/
@RestController
public class CaptchaController {@Autowiredprivate DefaultKaptcha defaultKaptcha;@ApiOperation(value = "验证码")@GetMapping(value = "/captcha",produces = "image/jpeg")public void captcha(HttpServletRequest request, HttpServletResponse response) {// 定义response输出类型为image/jpeg类型response.setDateHeader("Expires", 0);response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");response.addHeader("Cache-Control", "post-check=0, pre-check=0");response.setHeader("Pragma", "no-cache");response.setContentType("image/jpeg");// 开始生成验证码String text = defaultKaptcha.createText(); // 获取验证码文本内容System.out.println("验证码文本内容:" + text);request.getSession().setAttribute("captcha", text);BufferedImage image = defaultKaptcha.createImage(text); // 根据文本内容创建图形验证码ServletOutputStream outputStream = null;try {outputStream = response.getOutputStream();ImageIO.write(image, "jpg", outputStream); // 输出流输出图片,格式为jpgoutputStream.flush();} catch (IOException e) {e.printStackTrace();} finally {if (null != outputStream) {try {outputStream.close();} catch (IOException e) {e.printStackTrace();}}}// 生成验证码结束}
}
springboot 整合 谷歌 Captcha验证码相关推荐
- Springboot整合kaptcha实现验证码
验证码的作用 防止恶意破解密码.刷票.论坛灌水.刷页. 有效防止某个黑客对某一个特定注册用户用特定程序暴力破解方式进行不断的登录尝试,实际上使用验证码是现在很多网站通行的方式(比如招商银行的网上个人银 ...
- Spring 整合 Google Captcha 验证码
文章目录 验证码的作用 Google Captcha简介 Google Captcha 详细配置表 Spring MVC 整合 Google Captcha POM 创建 Spring 配置 Cont ...
- SpringBoot整合邮箱发送验证码
1.以QQ邮箱为例,点开设置开启POP3/SMTP服务 2.创建一个springboot项目 1)引入maven依赖 <dependency><groupId>org.spri ...
- SpringBoot整合qq邮箱验证码使用
目录 准备工作 依赖 yml配置 Config Service层接口 ServiceImpl实现 Controller层 准备工作 依赖 <dependency><groupId&g ...
- SpringBoot整合Captcha验证码(含代码)
1. 基本结构 使用Captcha生成验证码, 利用Redis存储验证码 Redis中的结构为, Key是32位的UUID, Value为Captcha的4位随机字母以及数字的集合 设定Redis过期 ...
- (二十三)admin-boot项目之captcha验证码整合
(二十三)captcha验证码整合 项目地址:https://gitee.com/springzb/admin-boot 如果觉得不错,给个 star 简介: 这是一个基础的企业级基础后端脚手架项目, ...
- SpringBoot整合Shiro实现权限控制,验证码
本文介绍 SpringBoot 整合 shiro,相对于 Spring Security 而言,shiro 更加简单,没有那么复杂. 目前我的需求是一个博客系统,有用户和管理员两种角色.一个用户可能有 ...
- Springboot 整合SpringSecurity实现账号密码+手机验证码登陆
Springboot 整合SpringSecurity实现账号密码+手机验证码登陆 示例说明 版本 示例安装 Spring-security 介绍 为什么不用 shiro Spring-Securit ...
- springmvc使用谷歌captcha生成图片验证码,并将验证码图片以二进制流的方式返回给前端(app和pc端都能调用)
近期对登录注册与获取短信验证码的接口做了安全限制,其中一部分就用到了谷歌的captcha验证码,比如当用户连续三次登陆失败,那么之后的登录请求就需要用户输入谷歌的图形验证码.由于web端和app端调用 ...
- Springboot整合kaptcha验证码
Springboot整合kaptcha验证码 01.通过配置类来配置kaptcha 01-01.添加kaptcha的依赖: <!-- kaptcha验证码 --> <dependen ...
最新文章
- 3天,我把MySQL索引、锁、事务、分库分表撸干净了!
- python潜力开源项目_10大Python开源项目推荐(Github平均star2135)
- python详细下载安装教程-Pycharm及python安装详细教程
- CentOS7-64bit 编译 Hadoop-2.5.0,并分布式安装
- lightoj1060_组合数学
- [Web开发] MySpace 发布开发接口
- 进程间通信管道进阶篇:linux下dup/dup2函数的用法
- 并行DA实验c语言程序,哈工大C语言DA实验报告.doc
- python del函数_python中del函数的垃圾回收
- z370支持pcie信号拆分吗_定了!AMD B550主板确认将支持PCIE4.0,多项能力接近X570
- ajax格式,需要指定交互的data类型
- 【转】化学怀旧风:用扑热息痛冲胶卷!
- matlab fx函数图像,matlab 画两个自变量的函数图像
- Mariadb 安装 启动 及错误 1067 问题解决
- PS小知识(三)——画圆滑线及虚线
- do还是doing imagine加to_“imagine to do”与“imagine doing”的区别是什么?
- 阿里云 ADAM 迁移工具测试问题记录
- Mac下安装Mavenidea配置maven
- python正则匹配中文/英文/数字/其它字符
- sql server为什么建表时在表名前加''[dbo]''
热门文章
- matlab的默认字体_matlab画图字体 matlab默认的字体是什么
- ubuntu上常用的软件安装
- 十大门店进销存管理系统软件测评,商陆花长年稳居排名榜首
- ibm刀片服务器如何装系统,详细分析如何安装和配置IBM刀片服务器
- Modern Python Cookbook》(Python经典实例)笔记 2.3 编写长行代码
- Python颜色空间转换(sRGB,AdobeRGB,CIE XYZ,Lab,HSV互转)
- 安装LoadRunner时提示缺少vc2005_sp1_with_atl_fix_redist解决方案
- linux open详解,Linux系统open函数详解
- Android MediaCodec学习笔记
- 关于无法卸载和安装VISIO2010的问题