PHPackages                             stayallive/random-tokens - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. stayallive/random-tokens

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stayallive/random-tokens
========================

Generate and handle prefixed random tokens.

v1.0.2(1y ago)77.2k↓30.2%3MITPHPPHP ^8.1CI passing

Since Feb 24Pushed 1y ago2 watchersCompare

[ Source](https://github.com/stayallive/random-tokens)[ Packagist](https://packagist.org/packages/stayallive/random-tokens)[ Docs](https://github.com/stayallive/random-tokens)[ GitHub Sponsors](https://github.com/stayallive)[ RSS](/packages/stayallive-random-tokens/feed)WikiDiscussions main Synced 1mo ago

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

Random Tokens
=============

[](#random-tokens)

[![Latest Version](https://camo.githubusercontent.com/d551efdd83d0cf9bd274888729853938e21131d8f969d06511db9cea12760061/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73746179616c6c6976652f72616e646f6d2d746f6b656e732e7376673f7374796c653d666c61742d737175617265)](https://github.com/stayallive/random-tokens/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/80abdb8ff60272bcaa3c987ed221eee2c3cd6b86955a0579d9b62c13090085d5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73746179616c6c6976652f72616e646f6d2d746f6b656e732f63692e79616d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/stayallive/random-tokens/actions/workflows/ci.yaml)[![Total Downloads](https://camo.githubusercontent.com/dec8907f126c8188d994a051418c538bae53e9e684c0cb014e0b3cbb06fa34f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746179616c6c6976652f72616e646f6d2d746f6b656e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stayallive/random-tokens)[![codecov](https://camo.githubusercontent.com/30763d30043d6b6f7ebfd3a4ed8334f6611f07c38e2dd3aa113b34851b7e8c37/68747470733a2f2f636f6465636f762e696f2f67682f73746179616c6c6976652f72616e646f6d2d746f6b656e732f67726170682f62616467652e7376673f746f6b656e3d4341334332564b344753)](https://codecov.io/gh/stayallive/random-tokens)

This package provides a simple way to generate prefixed random tokens inspired by the [GitHub token format](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/).

Tokens are comprised of the following parts:

- tokens always start with a prefix of 1-6 characters
- followed by a `_`
- followed by 30-242 characters of randomness (`a-zA-Z0-9`)
- followed by a 6 character base62 CRC32 checksum

A token cannot exceed 255 characters in total length.

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

[](#installation)

```
composer require stayallive/random-tokens
```

Usage
-----

[](#usage)

### Generating a token

[](#generating-a-token)

```
