| branch | CakePHP core | PHP min |
|---|---|---|
| 1.x | ^3.0 | PHP 7.2 |
| 2.x | ^4.0 | PHP 7.4 |
| 3.x | ^5.0 | PHP 8.1 |
This is a really "simple to use" CakePHP plugin for generating and reading temporaries tokens
composer require erwane/cakephp-token
bin/cake migrations migrate -p Token/**
* Create a token with data and return the id
* @param array $content an array of custom data
* @param string $expire expire exprimed in '+6 days +2 hours' format
* @param int $length Token length
* @return string The token id
*/
$myNewTokenId = \Token\Token::generate(array $content, $expire, 8);// return null (expired or not found) or Token entity
$token = \Token\Token::get($tokenId);Tokens deletion can be ignored, they will be destroyed on expire, but sometime you need to delete one token immediately
/**
* Delete token from id or entity
*
* @param \Token\Model\Entity\Token|string $token Token entity or id
* @return bool True if token was deleted
*/
$result = \Token\Token::delete($token);Each time a token is read, expired tokens are pruned