Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (60 sloc) 1.5 KB

Token

The Token generates and compares tokens.

Installation

composer require webiik/token

Example

$token = new \Webiik\Token\Token();
$secureToken = $token->generate();
if ($token->compare('vuefjsdfk', $secureToken)) {
    // Tokens are equal
}

Generating

generate

generate($strength = 16): string

generate() returns safe token. By default the token is 32 characters long. It throws Exception when it was not possible to generate safe token.

try {
    $token->generate();
} catch (Exception $exception) {
    // Unable to generate strong token
}

generateCheap

generateCheap($length = 32): string

generateCheap() returns cheap token. By default the token is 32 characters long. Cheap token is not safe, but is faster to generate.

$token->generateCheap();

Comparison

compare

compare(string $original, string $imprint): bool

compare() Compares two strings using the same time whether they're equal or not - Timing attack safe string comparison.

$token->compare('known-string', 'user-string');

Timing-attack safe comparison is slower than regular comparison.

Resources

You can’t perform that action at this time.