首页 > 其他分享 >SpringBoot增加验证码

SpringBoot增加验证码

时间:2024-07-18 17:33:51浏览次数:13  
标签:SpringBoot no httpServletResponse SpecCaptcha 验证码 captcha setCharType 增加

一、加入验证码依赖包


com.github.whvcse
easy-captcha
1.6.2

二、实现验证码控制层

@GetMapping("/common/kaptcha")
public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    httpServletResponse.setHeader("Cache-Control", "no-store");
    httpServletResponse.setHeader("Pragma", "no-cache");
    httpServletResponse.setDateHeader("Expires", 0);
    httpServletResponse.setContentType("image/png");

    // 三个参数分别为宽、高、位数
    SpecCaptcha captcha = new SpecCaptcha(150, 40, 4);

    // 设置类型 数字和字母混合
    captcha.setCharType(Captcha.TYPE_DEFAULT);

    //设置字体
    captcha.setCharType(Captcha.FONT_9);

    // 验证码存入session
    httpServletRequest.getSession().setAttribute("verifyCode", captcha.text().toLowerCase());

    // 输出图片流
    captcha.out(httpServletResponse.getOutputStream());
}

三、前端调用验证码接口 显示 图片
单击图片刷新!

四、效果如下

标签:SpringBoot,no,httpServletResponse,SpecCaptcha,验证码,captcha,setCharType,增加
From: https://www.cnblogs.com/velloLei/p/18310062

相关文章

  • Python web自动化爬虫-selenium/处理验证码/Xpath
    #coding:utf-8importtimeimportrandomfromtimeimportsleepfromcsvimportwriterfromseleniumimportwebdriverfromselenium.webdriver.common.byimportByfromchaojiyingimportChaojiying_Clientfromselenium.webdriverimportActionChainsdriver......
  • 基于springboot的小区物业管理系统
    全文内容包括:1、采用技术;2、系统功能;3、系统截图;4、配套内容。索取方式见文末微信号,欢迎关注收藏!一、采用技术语言:Java1.8框架:SpringBoot数据库:MySQL5.7、8.0开发工具:IntelliJIDEA旗舰版其他:Maven3.8以上二、系统功能物业人员管理:负责物业员工的信息录入、编辑、权限分......
  • 基于SpringBoot的宠物领养系统-07863(免费领源码+开发文档)可做计算机毕业设计JAVA、PHP
    摘 要21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所认识,科学化的管理,使信息存储达到准确、快速、完善,并能提高工作管理效率,促进其发展。论文主要是对宠物领养系统......
  • SpringBoot增加管理后台登录拦截器验证用户登录
    一、增加拦截器@ComponentpublicclassAdminLoginInterceptorimplementsHandlerInterceptor{@OverridepublicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponseresponse,Objecto)throwsException{StringrequestServletPath=request.getS......
  • springboot整合mqtt
    安装emqxhttps://blog.csdn.net/weixin_41542513/article/details/134328627springboot整合mqtt1、引入依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-integration&l......
  • springboot博客交流平台-计算机毕业设计源码56406
    摘要博客交流平台作为一种重要的网络平台,为用户提供了展示自我、分享经验和与他人互动的空间。在国内外,研究者们关注博客交流平台的各个方面,并取得了显著的进展。研究内容主要包括用户体验和界面设计、社交化和互动性、多媒体内容支持、移动设备适配和跨平台体验、数据分析......
  • springboot访问多个mysql数据库配置多数据源
    一、参考地址:https://github.com/baomidou/dynamic-datasource二、使用方法引入dynamic-datasource-spring-boot-starter或者dynamic-datasource-spring-boot3-starter。spring-boot1.5.x2.x.x点击查看代码<dependency><groupId>com.baomidou</groupId><art......
  • SpringBoot整合MyBatis+MySQL
    一、添加mysql驱动mysqlmysql-connector-java二、添加MyBatis依赖org.mybatis.spring.bootmybatis-spring-boot-starter3.0.1三、添加配置spring:datasource:name:xx-datasourcedriverClassName:com.mysql.cj.jdbc.Driverurl:jdbc:mysql://127.0.0.1:3306/xx-......
  • SpringBoot 跨域请求处理全攻略:从原理到实践
    文章目录SpringBoot如何处理跨域请求?你能说出几种方法?跨域请求概述跨域解决方案1.使用@CrossOrigin注解2.使用WebMvcConfigurer配置类3.使用过滤器(Filter)4.使用SpringSecurity处理CORS5.使用SpringCloudGateway处理CORS补充1.预检请求(PreflightRequests)2.其......
  • 使用Spring Boot实现图形验证码:从零开始的详细教程
    使用SpringBoot实现图形验证码:从零开始的详细教程在现代Web应用中,图形验证码是一种常见的防止机器人和恶意攻击的手段。今天,我们将深入探讨如何在SpringBoot项目中实现图形验证码。通过这个教程,你将学会如何生成和验证图形验证码,并将其集成到你的SpringBoot应用中。一、项目......