PHPackages                             veeqtoh/secure-code - 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. [Security](/categories/security)
4. /
5. veeqtoh/secure-code

ActiveLibrary[Security](/categories/security)

veeqtoh/secure-code
===================

A Laravel package for creating secure codes, providing unique and random n-digit codes for any use.

v2.0.0(2y ago)16101MITPHPPHP ^8.1

Since Aug 6Pushed 1y ago2 watchersCompare

[ Source](https://github.com/veeqtoh/secure-code)[ Packagist](https://packagist.org/packages/veeqtoh/secure-code)[ Docs](https://github.com/veeqtoh/secure-code)[ GitHub Sponsors](https://github.com/veeqtoh)[ RSS](/packages/veeqtoh-secure-code/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

secure-code
===========

[](#secure-code)

[![](https://camo.githubusercontent.com/478c4ec7291f55ad64ed92c1f79c5eaf8308f8442c8678be176e12de3dd244a5/68747470733a2f2f766963746f72756b616d2e636f6d2f6173736574732f696d616765732f7365637572652d636f64652e706e67)](https://camo.githubusercontent.com/478c4ec7291f55ad64ed92c1f79c5eaf8308f8442c8678be176e12de3dd244a5/68747470733a2f2f766963746f72756b616d2e636f6d2f6173736574732f696d616765732f7365637572652d636f64652e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/74e22f315967c3fd326866eabb0ceb25dde41c14475dc1ed1fc551802e8f5382/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76656571746f682f7365637572652d636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/veeqtoh/secure-code)[![PHP from Packagist](https://camo.githubusercontent.com/04b675276578c2a8d4582094edd30de8203dfc269f6697db1d2d6df26c79d99a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f76656571746f682f7365637572652d636f64653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/veeqtoh/secure-code)[![GitHub license](https://camo.githubusercontent.com/e9758aeaf1e6fee90f82123d789be978402b67747a3fe1b8ae762db6800bdb6e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f76656571746f682f7365637572652d636f64653f7374796c653d666c61742d737175617265)](https://github.com/veeqtoh/secure-code/blob/master/LICENSE)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install the Package](#install-the-package)
    - [Publish the Config and Migrations](#publish-the-config-and-migrations)
    - [Migrate the Database](#migrate-the-database)
- [Usage](#usage)
    - [Generating Secure Codes](#generating-secure-codess)
        - [Quick Start](#quick-start)
        - [Validation](#validation)
        - [Defining your Custom Validation Class](#defining-your-custom-validation-class)
        - [Customizing Configs](#customizing-configs)
        - [Facade](#facade)
    - [Using the Secure code Manager](#using-the-secure-code-manager)
        - [Allocating a Code](#allocating-a-code)
        - [Resetting a Code](#resetting-a-code)
        - [Destroying a Code](#destroying-a-code)
        - [Config Validation](#config-validation)
        - [Custom Database Connection](#custom-database-connection)
    - [Helper Methods](#helper-methods)
        - [Find by code](#find-by-code)
        - [Find by owner](#find-by-owner)
    - [Model Factories](#model-factories)
- [Testing](#testing)
- [Security](#security)
- [Contribution](#contribution)
- [Changelog](#changelog)
- [Upgrading](#upgrading)
- [License](#license)

Overview
========

[](#overview)

A Laravel package that provides secure codes management system, allowing you to generate n-digit secure codes and manage it's allocation within you existing web app.

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

[](#installation)

### Requirements

[](#requirements)

The package has been developed and tested to work with the following minimum requirements:

- PHP 8.x
- Laravel 11.x

Secure-code requires either the [BC Math](https://secure.php.net/manual/en/book.bc.php) or [GMP](https://secure.php.net/manual/en/book.gmp.php) PHP extensions in order to work.

### Install the Package

[](#install-the-package)

You can install the package via Composer:

```
composer require veeqtoh/secure-code
```

### Publish the Config and Migrations

[](#publish-the-config-and-migrations)

You can then publish the package's config file and database migrations by using the following command:

```
php artisan vendor:publish --provider="Veeqtoh\SecureCode\Providers\SecureCodeProvider"
```

### Migrate the Database

[](#migrate-the-database)

This package contains a migration file that add a new table to the database: `secure_codes`. To run this migration, simply run the following command:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Generating Secure Codes

[](#generating-secure-codes)

#### Quick Start

[](#quick-start)

The quickest way to get started with generating a secure code is by using the snippet below.

```
use Veeqtoh\SecureCode\Classes\CodeGenerator;

$codeGenerator = new CodeGenerator();
$secureCode    = $codeGenerator->generate();

echo "Generated code: $code";
```

#### Validation

[](#validation)

By default, the secure code is not validated against any condition. The library however, comes with three (3) inbuilt validation classes that checks for;

1. Palindrome.
2. Repeated characters.
3. Sequence length.

These validation classes can be initialized and passed down to the code generator class in an array on it's constructor as shown below;

```
use Veeqtoh\SecureCode\Classes\CodeGenerator;

// Define specific validation rules.
$validators = [
    new NoPalindromeValidator(),
    new RepeatingCharactersValidator(),
    new MinimumUniqueCharactersValidator(),
  ];

// Generate a secure n-digit code.
$codeGenerator = new CodeGenerator($validators);
$secureCode    = $codeGenerator->generate();

echo "Generated code: $code";
```

You may wish to define a custom validation yourself for more control. You can

#### Custom Validation

[](#custom-validation)

To achieve this, you must write a class that implements the library's base validation interface as follows;

##### Defining your custom validation class

[](#defining-your-custom-validation-class)

```
declare(strict_types=1);

namespace Your\Custom\Class\Namespace;

use Veeqtoh\SecureCode\Contracts\CodeValidator;

class YourCustomValidatorValidator implements CodeValidator
{

  public function isValid(string $code): bool
  {
      return 'your custom rule';
  }

}
```

To use your custom rule, simply initialize and include it in the validators array as shown above.

#### Customizing Configs

[](#customizing-configs)

Tailor the package to to your needs with customizable configuration options:

- Database Connection: Specify a custom database connection if needed.
- Code Generation Rules: Define code length and constraints like character repetition and unique characters limit.
- Code Format: Choose from numeric, alphanumeric, or mixed formats for generated codes.
- Code Characters: Customize character sets for different code formats.
- Config Validation: Optionally validate configuration for safety.
- Eloquent Factories: Define factories for testing purposes. With these options, you can configure the system to align with your security standards and requirements.

Note: The code length cannot be more than 19.

#### Facade

[](#facade)

If you prefer to use facades in Laravel, you can choose to use the provided `SecureCode` facade instead of instantiating the `CodeGenerator` class manually.

### Using the Secure Code Manager

[](#using-the-secure-code-manager)

The code manager provides functionality to manage generated access codes, including allocation, resetting, and destruction.

#### Allocating a Code

[](#allocating-a-code)

To allocate a code to an owner, you can use the allocateCode method:

```
use Veeqtoh\DoorAccess\Classes\CodeManager;

$manager = new CodeManager();
$code    = $manager->allocateCode('generated-code', 'owner-id');

echo "Allocated code: $code";
```

#### Resetting a Code

[](#resetting-a-code)

To reset a code and make it available for reallocation, you can use the resetCode method:

```
use Veeqtoh\DoorAccess\Classes\CodeManager;

$manager = new CodeManager();
$success = $manager->resetCode('allocated-code');

if ($success) {
    echo "Code reset successfully";
} else {
    echo "Failed to reset code";
}
```

#### Destroying a Code

[](#destroying-a-code)

To permanently destroy a code, you can use the destroyCode method:

```
use Veeqtoh\DoorAccess\Classes\CodeManager;

$manager = new CodeManager();
$success = $manager->destroyCode('code-to-destroy');

if ($success) {
    echo "Code destroyed successfully";
} else {
    echo "Failed to destroy code";
}
```

#### Config Validation

[](#config-validation)

By default, the values defined in the `secure-code.php` config file are validated as the library contains a validator that is used to ensure that your values are safe to use. To disable the config validation, you can set the following option in the config:

```
'validate_config' => false,

```

#### Custom Database Connection

[](#custom-database-connection)

By default, Secure code will use your application's default database connection. But there may be times that you'd like to use a different connection. For example, you might be building a multi-tenant application that uses a separate connection for each tenant, and you may want to store the Secure codes in a central database.

To do this, you can set the connection name using the `connection` config value in the `config/secure-code.php` file like so:

```
'connection' => 'custom_database_connection_name',

```

### Helper Methods

[](#helper-methods)

#### Find by code

[](#find-by-code)

To find the SecureCode model that corresponds to a given code, you can use the `->findByCode()` method.

For example, to find the SecureCode model of a code that has the code `abc123`, you could use the following:

```
$secureCode = \Veeqtoh\SecureCode\Models\SecureCode::findByCode('abc123');
```

#### Find by Owner

[](#find-by-owner)

To find the SecureCode models that belongs to a given owner ID, you can use the `->findByOwnerId()` method.

For example, to find all of the SecureCode models of owners that belongs to `john doe`, you could use the following:

```
$secureCodes = \Veeqtoh\SecureCode\Models\SecureCode::findByOwnerId('john doe');
```

### Model Factories

[](#model-factories)

The package comes with model factories included for testing purposes.

```
use Veeqtoh\SecureCode\Models\SecureCode;
```

Testing
-------

[](#testing)

To run the package's unit tests, run the following command:

```
vendor/bin/pest
```

Security
--------

[](#security)

If you find any security related issues, please contact me directly at  to report it.

Contribution
------------

[](#contribution)

If you wish to make any changes or improvements to the package, feel free to make a pull request.

Note: A contribution guide will be added soon.

Changelog
---------

[](#changelog)

Check the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes.

Upgrading
---------

[](#upgrading)

Check the [UPGRADE](UPGRADE.md) guide to get more information on how to update this library to newer versions.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Support Me
----------

[](#support-me)

If you've found this package useful, please consider sponsoring this project. It will encourage me to keep maintaining it.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% 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 ~271 days

Total

2

Last Release

744d ago

Major Versions

v1.0.0 → v2.0.02024-05-04

PHP version history (2 changes)v1.0.0PHP ^8.1.2

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d506cce25345d6a03f9a0acf7ae4b57fa21bc83d98cb73d2f3d6f10d1140bc3?d=identicon)[veeqtoh](/maintainers/veeqtoh)

---

Top Contributors

[![veeqtoh](https://avatars.githubusercontent.com/u/19429315?v=4)](https://github.com/veeqtoh "veeqtoh (104 commits)")[![xilent](https://avatars.githubusercontent.com/u/259646?v=4)](https://github.com/xilent "xilent (1 commits)")

---

Tags

access-controldoor-controllerlaravelphpsecuritylaravellaravel-packageunique codesveeqtohvictor-ukamsecure-codesecure-accesspersistent-codesrandom-code-allocationclock-inclock-outpalindromerepeated charactersunique characters

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/veeqtoh-secure-code/health.svg)

```
[![Health](https://phpackages.com/badges/veeqtoh-secure-code/health.svg)](https://phpackages.com/packages/veeqtoh-secure-code)
```

###  Alternatives

[ashallendesign/short-url

A Laravel package for creating shortened URLs for your web apps.

1.4k1.9M4](/packages/ashallendesign-short-url)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)

PHPackages © 2026

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