用户名/项目名称

不依赖框架的令牌生成器

1.0.0 2016-04-12 12:28 UTC

This package is auto-updated.

Last update: 2024-08-27 16:14:29 UTC


README

Latest Version on Packagist Software License Build Status Total Downloads

为PHP 7编写的、不依赖框架的令牌生成器。使用标量类型提示和返回类型提示。

将使用hash_hmac生成安全的令牌,并允许访问令牌值和过期日期,以便在存储中使用。也可以生成不安全的令牌,仅通过访问值即可,这对于CSRF令牌很有用。

安装

通过Composer

$ composer require nigelgreenway/signa

使用方法

<?php

require __DIR__.'/vendor/autoload.php';

$tokenGenerator = new \Signa\TokenGenerator('s0m3-s3cur3-k3y');

$tokenWithExpiry = $tokenGenerator->tokenWithExpiry(
    [
        'user_name' => 'Scooby Doo',
        'age'       => 7,
    ],
    new \DateTimeImmutable('+30 Days'),
    'sha256'
);

// A secure token, for password resets and such
echo "A secure token\n";
echo sprintf("Value: %s\n", $tokenWithExpiry->value()); // Some hash string
echo sprintf("Expires on: %s\n", $tokenWithExpiry->expiresOn()->format('Y-m-d H:i:s')); // 30 days from today, aka the future

// An insecure token, generally CSRF and such
echo "\nAn insecure token\n";
$insecureToken = $tokenGenerator->token(36);
echo sprintf("Value: %s (Length %d)\n", $insecureToken->value(), strlen($insecureToken->value())); // Some string, 36 char length

echo "\nAn insecure token with odd value\n";
$insecureToken = $tokenGenerator->token(33);
echo sprintf("Value: %s (Length: %d)\n", $insecureToken->value(), strlen($insecureToken->value())); // Some string, 33 char length

变更日志

请参阅变更日志了解最近的变化。

测试

$ composer test

贡献

请参阅贡献指南行为准则以获取详细信息。

安全性

如果您发现任何安全相关的问题,请通过电子邮件github@futurepixels.co.uk联系,而不是使用问题跟踪器。

鸣谢

许可协议

MIT许可协议(MIT)。请参阅许可文件获取更多信息。