webiik/token

The Token generates and compares tokens.

1.0 2019-02-28 21:18 UTC

This package is auto-updated.

Last update: 2024-04-29 03:51:24 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667

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