PHPackages                             wackowiki/freecap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. wackowiki/freecap

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

wackowiki/freecap
=================

freeCap CAPTCHA library

1.5.1(1mo ago)1381GPL-2.0-or-laterPHPPHP &gt;=8.2

Since Jul 10Pushed 1mo agoCompare

[ Source](https://github.com/WackoWiki/freecap)[ Packagist](https://packagist.org/packages/wackowiki/freecap)[ RSS](/packages/wackowiki-freecap/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

freeCap
=======

[](#freecap)

A modern, object-oriented CAPTCHA library for PHP 8.2+, originally created by Howard Yeend and maintained by the WackoWiki Team. freeCap uses GD to generate highly obfuscated, OCR-resistant CAPTCHA images.

This version has been completely refactored to support Composer, PSR-4 autoloading, custom session adapters, and strict standards. It retains all of the original's educational inline comments and OCR circumvention logic.

Features
--------

[](#features)

- **OCR Circumvention**: Implements character morphing (sine wave deviations), random fonts, background noise (grid, squiggles, morphed blocks), and blurring.
- **Brute Force Protection**: Locks out users after a configurable number of refresh attempts.
- **Dictionary &amp; Random Words**: Supports pulling words from a dictionary file or generating pseudo-random consonant-vowel strings.
- **Multiple Formats**: Supports outputting `avif`, `gif`, `jpg`, `png`, and `webp` images.
- **Session Adapter API**: Decouples session handling from the core logic, making it easy to integrate with any framework (`$_SESSION`, custom session objects, PSR-16 caches, etc.).
- **Graceful Fallbacks**: If custom GD fonts or dictionary files are missing, it safely falls back to built-in fonts and random word generation.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- GD Extension

Installation
------------

[](#installation)

Install via Composer:

```
composer require wackowiki/freecap
```

Directory Structure
-------------------

[](#directory-structure)

Ensure your `.ht_freecap_*` assets (fonts, dictionaries, background images) are placed in a `resources/` directory at the root of your project or package.

```
freecap/
├── resources/
│   ├── .ht_freecap_font1.gdf
│   ├── .ht_freecap_font2.gdf
│   ├── .ht_freecap_font3.gdf
│   ├── .ht_freecap_font4.gdf
│   ├── .ht_freecap_font5.gdf
│   ├── .ht_freecap_im1.jpg
│   ├── ...
│   └── .ht_freecap_words
├── src/
│   ├── AdapterInterface.php
│   ├── FreeCap.php
│   └── SessionAdapter.php
├── tests/
├── composer.json
└── LICENSE

```

Basic Usage
-----------

[](#basic-usage)

### 1. Rendering the CAPTCHA Image

[](#1-rendering-the-captcha-image)

In your routing or controller logic, initialize the adapter and call `render()`. This outputs the image directly to the browser with the correct `Content-Type` headers.

```
use FreeCap\FreeCap;
use FreeCap\SessionAdapter;

// 1. Initialize the adapter with your session mechanism
//    SessionAdapter accepts native arrays or objects with magic properties (like WackoWiki's)
$adapter = new SessionAdapter($_SESSION);

// 2. Optional: Pass custom configuration
$config = [
    'use_dict' => 1,
    'bg_type'  => 1,
    'output'   => 'webp',
];

// 3. Generate and render
$captcha = new FreeCap($adapter, $config);
$captcha->render(); // Exits script after sending image
```

### 2. Displaying in HTML

[](#2-displaying-in-html)

```

    Reload

```

### 3. Validating User Input

[](#3-validating-user-input)

In your form processing logic, verify the submitted word against the session hash. **Make sure to set the `freecap_shown` flag when the form page loads so the validator knows a CAPTCHA was issued.**

```
use FreeCap\FreeCap;
use FreeCap\SessionAdapter;

// When the form page is loaded, flag that the CAPTCHA is active:
// $adapter = new SessionAdapter($_SESSION);
// $adapter->set('freecap_shown', 1);

// On form submission:
$adapter = new SessionAdapter($_SESSION);
$captcha = new FreeCap($adapter);

$input = $_POST['captcha'] ?? '';

if ($captcha->validate($input)) {
    echo "CAPTCHA passed!";
} else {
    echo "CAPTCHA failed. Please try again.";
}
```

Configuration Options
---------------------

[](#configuration-options)

You can override default behaviors by passing an array to the `FreeCap` constructor.

```
$config = [
    'asset_path'       => '/path/to/resources',  // Defaults to ../resources
    'site_tags'        => null,                   // Array of strings to display on the image
    'tag_pos'          => 1,                      // 0: top, 1: bottom, 2: both
    'algo'             => 'sha1',                 // 'sha1', 'sha256', 'sha512'
    'output'           => 'webp',                 // 'avif', 'gif', 'jpg', 'png', 'webp'
    'use_dict'         => 1,                      // 0: random string, 1: dictionary file
    'max_word_length'  => 6,                      // Maximum characters in the CAPTCHA
    'col_type'         => 1,                      // 0: one color, 1: different color per letter
    'max_attempts'     => 15,                    // Max refresh attempts before lockout
    'bg_type'          => 1,                      // 0: transparent, 1: grid, 2: squiggles, 3: morphed blocks
    'blur_bg'          => true,                   // Blur the background?
    'morph_bg'         => true,                   // Morph the background?
    'merge_type'       => 0,                      // 0: merge CAPTCHA with bg, 1: write over bg
];

$captcha = new FreeCap($adapter, $config);
```

Custom Session Adapters
-----------------------

[](#custom-session-adapters)

If you are not using native PHP sessions, you can create your own adapter by implementing the `FreeCap\AdapterInterface`.

```
use FreeCap\AdapterInterface;

class MyCacheAdapter implements AdapterInterface
{
    private Cache $cache;

    public function __construct(Cache $cache)
    {
        $this->cache = $cache;
    }

    public function get(string $key, mixed $default = null): mixed
    {
        return $this->cache->get('captcha_' . $key, $default);
    }

    public function set(string $key, mixed $value): void
    {
        $this->cache->set('captcha_' . $key, $value);
    }

    public function delete(string $key): void
    {
        $this->cache->delete('captcha_' . $key);
    }
}
```

Testing
-------

[](#testing)

The package includes PHPUnit 11 tests. To run the test suite:

```
composer install
vendor/bin/phpunit tests
```

Credits
-------

[](#credits)

- **Howard Yeend** (solidred.co.uk) - Original author of freeCap v1.4.1
- **WackoWiki Team** - Modernization, OOP refactor, and maintenance (2008 - 2025)

License
-------

[](#license)

This project is licensed under the GNU General Public License v2.0 or later. See the `LICENSE` file for more details.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance90

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

48d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/54716082?v=4)[vendeeglobe](/maintainers/vendeeglobe)[@vendeeglobe](https://github.com/vendeeglobe)

---

Top Contributors

[![vendeeglobe](https://avatars.githubusercontent.com/u/54716082?v=4)](https://github.com/vendeeglobe "vendeeglobe (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wackowiki-freecap/health.svg)

```
[![Health](https://phpackages.com/badges/wackowiki-freecap/health.svg)](https://phpackages.com/packages/wackowiki-freecap)
```

###  Alternatives

[drupal/coder

Coder is a library to review Drupal code.

3046.8M631](/packages/drupal-coder)[hyperf/validation

hyperf validation

122.2M213](/packages/hyperf-validation)[udokmeci/yii2-phone-validator

Modern Yii2 Phone validator wrapper on top of PhoneNumberUtil library also used by Android devices

36227.5k1](/packages/udokmeci-yii2-phone-validator)[yii2mod/yii2-validators

Collection of useful validators for Yii Framework 2.0

1817.0k](/packages/yii2mod-yii2-validators)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
