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

ActiveLibrary[Security](/categories/security)

baohan/token
============

A password hash token

1.1.6(6y ago)056MITPHPPHP ^7.2

Since Oct 20Pushed 4y ago1 watchersCompare

[ Source](https://github.com/baohanddd/baohan-token)[ Packagist](https://packagist.org/packages/baohan/token)[ RSS](/packages/baohan-token/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (7)Used By (0)

Web Token
=========

[](#web-token)

标签（空格分隔）： 未分类

---

Example

```
require('vendor/autoload.php');

// to set up roles and relationships...
$roles = [
    'admin' => new \baohan\token\Role('admin'),
    'user'  => new \baohan\token\Role('user'),
    'guest' => new \baohan\token\Role('guest')
];

$roles['guest']->addSupervisor($roles['user']);
$roles['user']->addSupervisor($roles['admin']);

```

---

```
# to generate a token
// NOTE: private key is consist with 32 chars only...
$private_key = "i7p0TdjdOxAfl3mtrk9k99HCauZWyW4Y";
$token = new \baohan\token\Token(
    new \baohan\token\Crypto($private_key)
);
// to set role for the token
$token->setRole($roles['guest']);
// expire for token
$token->setExpire(time() + 3600);
// can output token as string...
echo $token;
// works too...
$authorization = (string) $token;
// works again...
$authorization = $token->serialize();

```

---

```
// to validate a token...
$t2 = new \baohan\token\Token(
    new \baohan\token\Crypto($private_key)
);
$t2->unserialize((string) $token);
$perm = new \baohan\token\Permission($t2);
var_dump($perm->is($roles['guest']));    // true
var_dump($perm->is($roles['user']));     // true
var_dump($perm->is($roles['admin']));    // true
var_dump($perm->alive());                // true

```

That's all. Enjoy it.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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 ~24 days

Total

6

Last Release

2275d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79f2348c437cf1a1aae2848beacc1adc2cae3d8be7faacbe28d5a3483225a367?d=identicon)[baohanddd](/maintainers/baohanddd)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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