{"id":24775219,"url":"https://github.com/veeqtoh/secure-code","last_synced_at":"2025-09-07T01:06:44.122Z","repository":{"id":238049263,"uuid":"674445850","full_name":"veeqtoh/secure-code","owner":"veeqtoh","description":"A Laravel package for generating and managing n-digit random secure codes for your app.","archived":false,"fork":false,"pushed_at":"2024-10-24T13:58:54.000Z","size":220,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-13T07:27:04.420Z","etag":null,"topics":["access-control","door-controller","laravel","php","security"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/veeqtoh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"veeqtoh"}},"created_at":"2023-08-04T01:20:03.000Z","updated_at":"2024-10-24T13:58:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"72438bd8-d853-48bd-aabf-731c38c7e948","html_url":"https://github.com/veeqtoh/secure-code","commit_stats":null,"previous_names":["veeqtoh/secure-code"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/veeqtoh/secure-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeqtoh%2Fsecure-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeqtoh%2Fsecure-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeqtoh%2Fsecure-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeqtoh%2Fsecure-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/veeqtoh","download_url":"https://codeload.github.com/veeqtoh/secure-code/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/veeqtoh%2Fsecure-code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273983139,"owners_count":25202101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["access-control","door-controller","laravel","php","security"],"created_at":"2025-01-29T06:40:07.445Z","updated_at":"2025-09-07T01:06:44.099Z","avatar_url":"https://github.com/veeqtoh.png","language":"PHP","funding_links":["https://github.com/sponsors/veeqtoh"],"categories":[],"sub_categories":[],"readme":"# secure-code\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://victorukam.com/assets/images/secure-code.png\" width=\"400\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://packagist.org/packages/veeqtoh/secure-code\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/veeqtoh/secure-code.svg?style=flat-square\" alt=\"Latest Version on Packagist\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/veeqtoh/secure-code\"\u003e\u003cimg src=\"https://img.shields.io/packagist/php-v/veeqtoh/secure-code?style=flat-square\" alt=\"PHP from Packagist\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/veeqtoh/secure-code/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/veeqtoh/secure-code?style=flat-square\" alt=\"GitHub license\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Overview](#overview)\n- [Installation](#installation)\n    - [Requirements](#requirements)\n    - [Install the Package](#install-the-package)\n    - [Publish the Config and Migrations](#publish-the-config-and-migrations)\n    - [Migrate the Database](#migrate-the-database)\n- [Usage](#usage)\n    - [Generating Secure Codes](#generating-secure-codess)\n        - [Quick Start](#quick-start)\n        - [Validation](#validation)\n        - [Defining your Custom Validation Class](#defining-your-custom-validation-class)\n        - [Customizing Configs](#customizing-configs)\n        - [Facade](#facade)\n    - [Using the Secure code Manager](#using-the-secure-code-manager)\n        - [Allocating a Code](#allocating-a-code)\n        - [Resetting a Code](#resetting-a-code)\n        - [Destroying a Code](#destroying-a-code)\n        - [Config Validation](#config-validation)\n        - [Custom Database Connection](#custom-database-connection)\n    - [Helper Methods](#helper-methods)\n        - [Find by code](#find-by-code)\n        - [Find by owner](#find-by-owner)\n    - [Model Factories](#model-factories)\n- [Testing](#testing)\n- [Security](#security)\n- [Contribution](#contribution)\n- [Changelog](#changelog)\n- [Upgrading](#upgrading)\n- [License](#license)\n\n# Overview\n\nA 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.\n\n## Installation\n\n\n### Requirements\n\nThe package has been developed and tested to work with the following minimum requirements:\n\n- PHP 8.x\n- Laravel 11.x\n\nSecure-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.\n\n### Install the Package\n\nYou can install the package via Composer:\n\n```bash\ncomposer require veeqtoh/secure-code\n```\n\n### Publish the Config and Migrations\n\nYou can then publish the package's config file and database migrations by using the following command:\n```bash\nphp artisan vendor:publish --provider=\"Veeqtoh\\SecureCode\\Providers\\SecureCodeProvider\"\n```\n\n### Migrate the Database\n\nThis package contains a migration file that add a new table to the database: ``` secure_codes ```. To run this migration, simply run the following command:\n```bash\nphp artisan migrate\n```\n\n## Usage\n\n### Generating Secure Codes\n\n#### Quick Start\n\nThe quickest way to get started with generating a secure code is by using the snippet below.\n```php\nuse Veeqtoh\\SecureCode\\Classes\\CodeGenerator;\n\n$codeGenerator = new CodeGenerator();\n$secureCode    = $codeGenerator-\u003egenerate();\n\necho \"Generated code: $code\";\n```\n\n#### Validation\n\nBy default, the secure code is not validated against any condition. The library however, comes with three (3) inbuilt validation classes that checks for;\n1. Palindrome.\n2. Repeated characters.\n3. Sequence length.\n\nThese validation classes can be initialized and passed down to the code generator class in an array on it's constructor as shown below;\n\n```php\nuse Veeqtoh\\SecureCode\\Classes\\CodeGenerator;\n\n// Define specific validation rules.\n$validators = [\n    new NoPalindromeValidator(),\n    new RepeatingCharactersValidator(),\n    new MinimumUniqueCharactersValidator(),\n  ];\n\n// Generate a secure n-digit code.\n$codeGenerator = new CodeGenerator($validators);\n$secureCode    = $codeGenerator-\u003egenerate();\n\necho \"Generated code: $code\";\n```\nYou may wish to define a custom validation yourself for more control. You can\n\n#### Custom Validation\n\nTo achieve this, you must write a class that implements the library's base validation interface as follows;\n\n##### Defining your custom validation class\n\n```php\ndeclare(strict_types=1);\n\nnamespace Your\\Custom\\Class\\Namespace;\n\nuse Veeqtoh\\SecureCode\\Contracts\\CodeValidator;\n\nclass YourCustomValidatorValidator implements CodeValidator\n{\n\n  public function isValid(string $code): bool\n  {\n      return 'your custom rule';\n  }\n\n}\n```\nTo use your custom rule, simply initialize and include it in the validators array as shown above.\n\n#### Customizing Configs\n\nTailor the package to to your needs with customizable configuration options:\n\n- Database Connection: Specify a custom database connection if needed.\n- Code Generation Rules: Define code length and constraints like character repetition and unique characters limit.\n- Code Format: Choose from numeric, alphanumeric, or mixed formats for generated codes.\n- Code Characters: Customize character sets for different code formats.\n- Config Validation: Optionally validate configuration for safety.\n- Eloquent Factories: Define factories for testing purposes.\nWith these options, you can configure the system to align with your security standards and requirements.\n\nNote: The code length cannot be more than 19.\n\n#### Facade\n\nIf you prefer to use facades in Laravel, you can choose to use the provided ``` SecureCode ``` facade instead of instantiating\nthe ``` CodeGenerator ``` class manually.\n\n\n### Using the Secure Code Manager\n\nThe code manager provides functionality to manage generated access codes, including allocation, resetting, and destruction.\n\n#### Allocating a Code\n\nTo allocate a code to an owner, you can use the allocateCode method:\n\n```php\nuse Veeqtoh\\DoorAccess\\Classes\\CodeManager;\n\n$manager = new CodeManager();\n$code    = $manager-\u003eallocateCode('generated-code', 'owner-id');\n\necho \"Allocated code: $code\";\n```\n\n#### Resetting a Code\n\nTo reset a code and make it available for reallocation, you can use the resetCode method:\n\n```php\nuse Veeqtoh\\DoorAccess\\Classes\\CodeManager;\n\n$manager = new CodeManager();\n$success = $manager-\u003eresetCode('allocated-code');\n\nif ($success) {\n    echo \"Code reset successfully\";\n} else {\n    echo \"Failed to reset code\";\n}\n\n```\n\n#### Destroying a Code\n\nTo permanently destroy a code, you can use the destroyCode method:\n\n```php\nuse Veeqtoh\\DoorAccess\\Classes\\CodeManager;\n\n$manager = new CodeManager();\n$success = $manager-\u003edestroyCode('code-to-destroy');\n\nif ($success) {\n    echo \"Code destroyed successfully\";\n} else {\n    echo \"Failed to destroy code\";\n}\n\n```\n\n#### Config Validation\nBy default, the values defined in the ``` secure-code.php ``` config file are validated as the library contains\na validator that is used to ensure that your values are safe to use. To disable the config validation, you can set the\nfollowing option in the config:\n\n```\n'validate_config' =\u003e false,\n```\n\n#### Custom Database Connection\n\nBy 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.\n\nTo do this, you can set the connection name using the `connection` config value in the `config/secure-code.php` file like so:\n\n```\n'connection' =\u003e 'custom_database_connection_name',\n```\n\n\n### Helper Methods\n\n#### Find by code\nTo find the SecureCode model that corresponds to a given code, you can use the ``` -\u003efindByCode() ``` method.\n\nFor example, to find the SecureCode model of a code that has the code ``` abc123 ```, you could use the following:\n\n```php\n$secureCode = \\Veeqtoh\\SecureCode\\Models\\SecureCode::findByCode('abc123');\n``` \n\n#### Find by Owner\n\nTo find the SecureCode models that belongs to a given owner ID, you can use the ``` -\u003efindByOwnerId() ``` method.\n\nFor example, to find all of the SecureCode models of owners that belongs to ``` john doe ```, you could use\nthe following:\n\n```php\n$secureCodes = \\Veeqtoh\\SecureCode\\Models\\SecureCode::findByOwnerId('john doe');\n```\n\n### Model Factories\n\nThe package comes with model factories included for testing purposes.\n\n```php\nuse Veeqtoh\\SecureCode\\Models\\SecureCode;\n\n```\n\n## Testing\n\nTo run the package's unit tests, run the following command:\n\n``` bash\nvendor/bin/pest\n```\n\n## Security\n\nIf you find any security related issues, please contact me directly at [victorjohnukam@gmail.com](mailto:victorjohnukam@gmail.com) to report it.\n\n## Contribution\n\nIf you wish to make any changes or improvements to the package, feel free to make a pull request.\n\nNote: A contribution guide will be added soon.\n\n## Changelog\n\nCheck the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes.\n\n## Upgrading\n\nCheck the [UPGRADE](UPGRADE.md) guide to get more information on how to update this library to newer versions.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Support Me\n\nIf you've found this package useful, please consider sponsoring this project. It will encourage me to keep maintaining it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeqtoh%2Fsecure-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveeqtoh%2Fsecure-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveeqtoh%2Fsecure-code/lists"}