开源验证码生成工具(nkaptcha for Java)

nkaptcha是一款用于Java的验证码库,它不依赖于其他库,易于设置和使用,具有高可用性和高性能。用户可以轻松地更改验证码图片的样式,支持自定义扭曲代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开源地址:https://github.com/shuaijunlan/nkaptcha

nkaptcha

Build Status License codecov

nkaptcha is a verification code library for Java, it doesn’t rely on any other libraries, is very easy to setup and use, is high availability and high performance . If you would like to change the style of the verification code image, there is several configuration options and the framework is modular so you can write your own morphing code.

If you have a valid issue with the functionality or design of nkaptcha, please click the Issues page and file one.

Verification Code Verification Code

Features

Installation

  • Buid by maven:
<repositories>
    <repository>
        <id>shuaijunlan-github-maven-repository</id>
        <name>shuaijunlan-github-maven-repository</name>
        <url>https://raw.githubusercontent.com/shuaijunlan/shuaijunlan.github.io/master</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <artifactId>nkaptcha</artifactId>
        <groupId>io.github.shuaijunlan</groupId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

Get Started

You can generate verification code picture like this:

  • Output to folder by default properties
VerificationList verificationList = new VerificationList();
BufferedImage bufferedImage = verificationList.pop().getBufferedImage();
String formatName = "jpg";
String pathName = "F:\\test\\" + System.currentTimeMillis() + ".jpg";
ImageIO.write(bufferedImage,
        formatName,
        new File(pathName));
  • In web application by default properties
@GetMapping("nkaptcha")
public void nkaptcha(HttpServletResponse httpServletResponse) throws IOException {
    VerificationList verificationList = new VerificationList(properties);
    String formatName = "jpg";
    ImageIO.write(verificationList.pop().getBufferedImage(),
            formatName,
            httpServletResponse.getOutputStream());
}
  • Also you can change the properties by yourself
Properties properties = new Properties();
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_LINE, "true");
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_POINT, "false");
properties.setProperty(ParamKeyConstants.NKAPTCHA_IMAGE_NOISE_LINE_COUNT, "10");
VerificationList verificationList = new VerificationList(properties);
BufferedImage bufferedImage = verificationList.pop().getBufferedImage();
String formatName = "jpg";
ImageIO.write(verificationList.pop().getBufferedImage(),
              formatName,
              httpServletResponse.getOutputStream());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值