sFire PHP Framework

Token

sFire\Hash\Token provides an easy interface for creating unique id's and tokens.

In this section we will handle:

  • How to create a unique id
  • How to create a token

Create unique id

To generate a unique id you can use the uniqueId method. This methods accepts one parameter which is an Integer between 1 and 30 (default 10).

Note: The lower the number, the greater the chance of a collision.

Parameters
Token :: uniqueId([integer $length]);
Example
$id1 = Token :: uniqueId(); //Output similar to "0xXjXY7uqG"
$id2 = Token :: uniqueId(25); //Output similar to "GgVFE2pXAlW4PFMNv6AQS$uMZ"

Create a token

To generate a token you can use the create method. This method will return a String and accepts 5 arguments. You can included numbers, letters, capital letters and symbols.

Parameters
Token :: create([integer $length, boolean $numbers, boolean $letters, boolean $capitals, boolean $symbols]);
Example
$token1 = Token :: create(); //Output similar to "643105"
$token2 = Token :: create(48, true, false); //Output similar to "097910630096143219773204807686845632669487649630"
$token3 = Token :: create(64, true, false, false, true); //Output similar to "99358267-0#3%83%20!#300%1.-88+4.-+%#85$$$14.$#$-8.*6!@@#@3+&#$8$"