gsylvestre/php-token-generator

Generate crypto-secure URL safe strings

v0.1 2019-12-09 09:49 UTC

This package is auto-updated.

Last update: 2024-11-22 09:22:02 UTC


README

Simple yet secure token generator for PHP7.

  • Crypto-secure
  • Strings can be used in URLs
  • Optionnaly remove similar characters (Il1 and 0oO)
  • You choose the returned string length

Installation

composer require gsylvestre/php-token-generator

Usage

$generator = new \PHPTokenGenerator\TokenGenerator();
$token = $generator->generate(24); //RDTAwiMFSZiTs5y3Eqq7b9ud

Other usages

Default string length is 32:

$generator = new \PHPTokenGenerator\TokenGenerator();
$token = $generator->generate(); //MpWUMGLUeg6FQQr6CHi7S8n9tfapY2bc 

By default, the characters Il10oO are removed from returned string (because they look alike and cause errors when human reading is required). You can still get them by passing false as second argument :

$generator = new \PHPTokenGenerator\TokenGenerator();
$token = $generator->generate(12, false); //9tIKdlfCSOo4

License

MIT