当前位置:网站首页>Implement verification code verification
Implement verification code verification
2022-07-03 12:21:00 【Midsummer month 28】
Import dependence
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3.2</version>
</dependency>
Code implementation
@Controller
public class VerificationCodeController {
@Resource
private DefaultKaptcha defaultKaptcha;
@GetMapping("/common/kaptcha")
public void defaultKaptch(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) throws IOException {
byte[] captchaOutPutStream = null;
// Array byte output stream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
// Save the generated verification code to session in
String kaptchaText = defaultKaptcha.createText();
httpServletRequest.getSession().setAttribute("verifyCode",kaptchaText);
BufferedImage image = defaultKaptcha.createImage(kaptchaText);
ImageIO.write(image,"jpg",byteArrayOutputStream);
} catch (IOException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
captchaOutPutStream = byteArrayOutputStream.toByteArray();
httpServletResponse.setHeader("Cache-Control", "no-store");
httpServletResponse.setHeader("Pragma", "no-cache");
httpServletResponse.setDateHeader("Expires", 0);
httpServletResponse.setContentType("image/jpeg");
ServletOutputStream responseOutputStream = httpServletResponse.getOutputStream();
responseOutputStream.write(captchaOutPutStream);
responseOutputStream.flush();
responseOutputStream.close();
}
}
package com.cheng.controller.common;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import sun.security.krb5.KrbException;
import java.util.Properties;
@Component
public class KaptchaConfig {
@Bean
public DefaultKaptcha getDefaultKaptcha() {
com.google.code.kaptcha.impl.DefaultKaptcha defaultKaptcha = new com.google.code.kaptcha.impl.DefaultKaptcha();
Properties properties = new Properties();
properties.put("kaptcha.border","no");
properties.put("kaptcha.textproducer.font.color", "black");
properties.put("kaptcha.image.width", "150");
properties.put("kaptcha.image.height", "40");
properties.put("kaptcha.textproducer.font.size", "30");
properties.put("kaptcha.session.key", "verifyCode");
properties.put("kaptcha.textproducer.char.space", "5");
Config config = new Config(properties);
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
}
design sketch

边栏推荐
- [combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
- Dart: self study system
- ArcGIS application (XXI) ArcMap method of deleting layer specified features
- Php Export word method (One MHT)
- (construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
- repo Manifest Format
- Talk about the state management mechanism in Flink framework
- Pragma pack syntax and usage
- 2.6 preliminary cognition of synergetic couroutines
- Dart: about Libraries
猜你喜欢

Fluent: Engine Architecture

New features of ES6

Shardingsphere sub database and sub table < 3 >
![[MySQL special] read lock and write lock](/img/ac/e01c26882cc664ea2e5e731c5a8bab.png)
[MySQL special] read lock and write lock

云计算未来 — 云原生

Vulnhub's Nagini

Symlink(): solution to protocol error in PHP artisan storage:link on win10
![[official MySQL document] deadlock](/img/2d/04e97d696f20c2524701888ea9cd10.png)
[official MySQL document] deadlock

Solve msvcp120d DLL and msvcr120d DLL missing

win10 上PHP artisan storage:link 出现 symlink (): Protocol error的解决办法
随机推荐
Quantitative calculation research
Wechat applet - basic content
Self made pop-up input box, input text, and click to complete the event.
error: expected reference but got (raw string)
Solve msvcp120d DLL and msvcr120d DLL missing
1-1 token
Flutter Widget : KeyedSubtree
242. Effective letter heteronyms
repo Manifest Format
DEJA_ Vu3d - 054 of cesium feature set - simulate the whole process of rocket launch
Kubernetes three dozen probes and probe mode
LeetCode 0556.下一个更大元素 III - 4步讲完
Pragma pack syntax and usage
shardingSphere分库分表<3>
QT OpenGL texture map
023 ([template] minimum spanning tree) (minimum spanning tree)
ES6 standard
SystemVerilog -- OOP -- copy of object
(construction notes) learning experience of MIT reading
DEJA_VU3D - Cesium功能集 之 053-地下模式效果