Download the PHP package stayallive/random-tokens without Composer
On this page you can find all versions of the php package stayallive/random-tokens. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stayallive/random-tokens
More information about stayallive/random-tokens
Files in stayallive/random-tokens
Package random-tokens
Short Description Generate and handle prefixed random tokens.
License MIT
Homepage https://github.com/stayallive/random-tokens
Informations about the package random-tokens
Random Tokens
This package provides a simple way to generate prefixed random tokens inspired by the GitHub token format.
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
Usage
Generating a token
Validating a token
Storing a token
It's recommended to never store the token in plain text depending on your use case.
It's not needed to store the checksum as it can be recalculated from the random part of the token and since the prefix is usually static it's not needed to store that either.
You can store the token in a hashed format using the RandomToken::hash(binary: false) method.
This method will hash the random part of the token using SHA-256 and return a string with 64 characters.
Alternatively you can pass true as the binary argument to hash() to get the raw binary output of 32 bytes.
If you store information about the token in the cache you can also use RandomToken::cacheKey() to get a cache key for the token.
The cache key is constructed as token:<prefix>:<hash>, where <prefix> is the prefix of the token and <hash> is the SHA-256 hash of the random part of the token.
Security Vulnerabilities
If you discover a security vulnerability within this package, please send an e-mail to Alex Bouma at [email protected]. All security vulnerabilities will be swiftly
addressed.
License
This package is open-sourced software licensed under the MIT license.