Skip to content

Commit

Permalink
Introduction of Builder-oriented Version 2.0.0 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yaforster committed Dec 7, 2023
1 parent cc38853 commit fcb7521
Show file tree
Hide file tree
Showing 66 changed files with 1,504 additions and 2,938 deletions.
65 changes: 29 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
# flexcaptcha
A minimalistic CAPTCHA generator and validator, with customizable rendering options ready for both web and desktop applications. The image manipulation is done through [https://github.com/ajmas/JH-Labs-Java-Image-Filters](https://github.com/ajmas/JH-Labs-Java-Image-Filters).

A minimalistic CAPTCHA generator and validator, with customizable rendering options ready for both
web and desktop
applications. The image manipulation is done
through [https://github.com/ajmas/JH-Labs-Java-Image-Filters](https://github.com/ajmas/JH-Labs-Java-Image-Filters).

## Usage
### text-based CAPTCHA:

```java
SimpleCaptchaTextGenerator generator = new SimpleCaptchaTextGenerator(); //Can generate randomized strings from a pool of allowed characters
String s = generator.generate(10, Case.UPPERCASE); //Here is my random string. I want all letters to be uppercase. lowercase and mixed-case is supported, too. Or you supply your own string.
String pw = "ThisIsMyPassword"; //Supply a password for encryption

SimpleTextImageRenderer renderer = new SimpleTextImageRenderer(); //pick a renderer controlling the image generation (and distortion)
CipherHandler ch = new CipherHandler(); //Cipherhandler for implementing the encryption and decryption

TextCaptchaHandler handler = new SimpleTextCaptchaHandler();
String saltSource = "Hello World!"; //A salt source for salting the hashes and encryption
TextCaptcha captcha = handler.toCaptcha(s, ch, saltSource, pw, renderer , 100, 300); //putting it all together
AbstractCaptchaRenderer renderer=CaptchaRenderer.getDefaultCaptchaRenderer();
AbstractCaptchaCipher captchaCipher=CaptchaCipher.builder()
.expirationTimeSettings(new ExpirationTimeSettings(560L,()->System.currentTimeMillis()))
.build();

AbstractCaptchaGenerator generator=new CaptchaGenerator(captchaCipher,renderer);
String solution="abc123";
String salt="someSerializable";
Captcha captcha=generator.generate(solution,salt);
```
#### Sample images:

![5W3QRKCYMY](https://user-images.githubusercontent.com/96397624/148242974-931e21b9-de0c-4200-ad99-41c3e3918228.png)

![B6JJRT9XSD](https://user-images.githubusercontent.com/96397624/148242976-62a6e567-f2e0-43cf-87ac-43ea03aef6a9.png)

![bbmsjgwf4w](https://user-images.githubusercontent.com/96397624/148242978-1037e9a1-7b19-48e7-86e3-8896bb33306d.png)

![FqF](https://user-images.githubusercontent.com/96397624/148242981-d7889d63-5850-40a7-b913-9f66b9fe478d.png)

![m43geumhk8](https://user-images.githubusercontent.com/96397624/148242983-53876334-f87f-483e-93c9-9f63ff958e8e.png)
Alternatively, an arbitrary chain of effects can be used to further manipulate the rendered image:

```java
TwirlFilter filter=new TwirlFilter();
float twirlStrength=-0.3f;
filter.setAngle(twirlStrength);

AbstractCaptchaRenderer renderer=CaptchaRenderer.builder()
.imageOperationsList(Collections.singletonList(filter))
.build();

### image-based CAPTCHA:
AbstractCaptchaCipher captchaCipher=CaptchaCipher.builder()
.expirationTimeSettings(new ExpirationTimeSettings(560L,()->System.currentTimeMillis()))
.build();

```java
ImageCaptchaHandler handler = new SimpleImageCaptchaHandler();
CipherHandler ch = new CipherHandler();
ImageLoader loader = new ImageLoader();

BufferedImage[] solutionImages = loader.getImagesfromPath("C:\\SomeDirectory");
BufferedImage[] fillImages = loader.getImagesfromPath("C:\\SomeOtherDirectory");

String saltSource = "Hello World!";
int gridWidth = 3;
ImageCaptcha captcha = handler.generate(gridWidth, ch, saltSource, password, solutionImages, fillImages);
AbstractCaptchaGenerator generator=new CaptchaGenerator(captchaCipher,renderer);
String solution=generateCaptchaSolution();
Captcha captcha=generator.generate(solution,salt);
```
## Dependency

```
<dependency>
<groupId>io.github.yaforster</groupId>
<artifactId>flexcaptcha</artifactId>
<version>1.2.8</version>
<version>2.0.0</version>
</dependency>
```
22 changes: 18 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
A minimalistic and performant CAPTCHA generator and validator, with customizable rendering options ready for both web and desktop applications.
The image manipulation is done through [https://github.com/ajmas/JH-Labs-Java-Image-Filters](https://github.com/ajmas/JH-Labs-Java-Image-Filters).
A minimalistic and performant CAPTCHA generator and validator, with customizable rendering options
ready for both web
and desktop applications.
The image manipulation is done
through [https://github.com/ajmas/JH-Labs-Java-Image-Filters](https://github.com/ajmas/JH-Labs-Java-Image-Filters).

CAPTCHAs generated by flexcaptcha are highly customizable and can be generated and validated in different ways through the same application simultaneously. Thanks to this, flexcaptcha can be used as a centralized service for your web application landscape, or as a microservice, to hand out and validate CAPTCHAs that are tailored to each individual application that uses it.
CAPTCHAs generated by flexcaptcha are highly customizable and can be generated and validated in
different ways through
the same application simultaneously. Thanks to this, flexcaptcha can be used as a centralized
service for your web
application landscape, or as a microservice, to hand out and validate CAPTCHAs that are tailored to
each individual
application that uses it.

The generated image data and tokens are not permanently stored in a database, improving response times and ease of use in your application besides not requiring additional infrastructure to set up.
The generated image data and tokens are not permanently stored in a database, improving response
times and ease of use
in your application besides not requiring additional infrastructure to set up.

# Usage

## text-based CAPTCHA:

```java
Expand All @@ -20,6 +32,7 @@ The generated image data and tokens are not permanently stored in a database, im
String saltSource = "Hello World!"; //A salt source for salting the hashes and encryption
TextCaptcha captcha = handler.toCaptcha(s, ch, saltSource, pw, renderer , 100, 300); //putting it all together
```

### Sample images:

![5W3QRKCYMY](https://user-images.githubusercontent.com/96397624/148242974-931e21b9-de0c-4200-ad99-41c3e3918228.png)
Expand All @@ -46,6 +59,7 @@ The generated image data and tokens are not permanently stored in a database, im
int gridWidth = 3;
ImageCaptcha captcha = handler.generate(gridWidth, ch, saltSource, password, solutionImages, fillImages);
```

# Dependency

```
Expand Down
191 changes: 93 additions & 98 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,146 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>flexcaptcha</artifactId>
<groupId>io.github.yaforster</groupId>
<name>Flexible Captcha</name>
<description>Simple Captcha generation and validation</description>
<version>1.2.8</version>
<url>https://github.com/yaforster/flexcaptcha</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<developerConnection>scm:[email protected]:4ster1751/flexcaptcha.git</developerConnection>
<url>https://github.com/4ster1751/flexcaptcha.git</url>
</scm>
<developers>
<developer>
<id>yaforster</id>
<name>Yannick Forster</name>
<email>[email protected]</email>
<roles>
<role>developer</role>
</roles>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.basedir>${basedir}/../..</main.basedir>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jvm.options>--illegal-access=permit</jvm.options>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jhlabs/filters -->
<dependency>
<groupId>com.jhlabs</groupId>
<artifactId>filters</artifactId>
<version>2.0.235-1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<!--configure Maven to deploy to the OSSRH Nexus Repository Manager -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<serverId>ossrh</serverId>
</configuration>
<extensions>true</extensions>
<groupId>org.sonatype.plugins</groupId>
<version>1.6.13</version>
</plugin>
<!--get Source jar files generated -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
<id>attach-sources</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.3.0</version>
</plugin>
<!--get Javadoc files generated -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<id>attach-javadocs</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.6.2</version>
</plugin>
<!--sign the components -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<id>sign-artifacts</id>
<phase>verify</phase>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<scope>provided</scope>
<version>1.18.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<artifactId>commons-lang3</artifactId>
<groupId>org.apache.commons</groupId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jhlabs/filters -->
<dependency>
<artifactId>filters</artifactId>
<groupId>com.jhlabs</groupId>
<version>2.0.235-1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
<scope>test</scope>
<version>5.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<description>Simple Captcha generation and validation</description>
<developers>
<developer>
<email>[email protected]</email>
<id>yaforster</id>
<name>Yannick Forster</name>
<roles>
<role>developer</role>
</roles>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<groupId>io.github.yaforster</groupId>
<licenses>
<license>
<distribution>repo</distribution>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<modelVersion>4.0.0</modelVersion>
<name>Flexible Captcha</name>
<properties>
<jvm.options>--illegal-access=permit</jvm.options>
<main.basedir>${basedir}/../..</main.basedir>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<scm>
<developerConnection>scm:[email protected]:4ster1751/flexcaptcha.git</developerConnection>
<url>https://github.com/4ster1751/flexcaptcha.git</url>
</scm>
<url>https://github.com/yaforster/flexcaptcha</url>
<version>2.0.0</version>
</project>
24 changes: 0 additions & 24 deletions src/main/java/io/github/yaforster/flexcaptcha/Captcha.java

This file was deleted.

Loading

0 comments on commit fcb7521

Please sign in to comment.