PHPackages                             devious507/token-guard - 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. devious507/token-guard

ActiveLibrary

devious507/token-guard
======================

Simple SHA-256 bearer token guard middleware for PHP

02↓66.7%PHP

Since Jul 20Pushed 1mo agoCompare

[ Source](https://github.com/devious507/token-guard)[ Packagist](https://packagist.org/packages/devious507/token-guard)[ RSS](/packages/devious507-token-guard/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

TokenGuard
==========

[](#tokenguard)

Simple SHA-256 bearer token guard middleware for PHP.

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

[](#requirements)

- PHP &gt;= 7.4

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

[](#installation)

```
composer require devious507/token-guard
```

Usage
-----

[](#usage)

```
use App\Lib\TokenGuard;

// Pass the expected SHA-256 hash of your secret token
$guard = new TokenGuard('5e884898da28047d916453fb47e4ba6b0f07b4c3c8d5e9a7a3c9d2b5f8e4a1c');

// Call at the top of any protected script or route
$guard->enforce();

// Request continues here if token is valid
```

Generating the Hash
-------------------

[](#generating-the-hash)

```
php -r "echo hash('sha256', 'your-secret-token');"
```

How It Works
------------

[](#how-it-works)

- Reads the `Authorization: Bearer ` header from the incoming request
- Computes `SHA-256` of the presented token
- Compares against the expected hash using `hash_equals()` (timing-safe)
- Returns `401` with JSON error on mismatch or missing token

Supports Apache (`$_SERVER['HTTP_AUTHORIZATION']`), Nginx (`REDIRECT_HTTP_AUTHORIZATION`), and `getallheaders()`.

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance60

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/devious507-token-guard/health.svg)

```
[![Health](https://phpackages.com/badges/devious507-token-guard/health.svg)](https://phpackages.com/packages/devious507-token-guard)
```

PHPackages © 2026

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