malahierba-lab/token
最新稳定版本:1.0.1
Composer 安装命令:
composer require malahierba-lab/token
包简介
Laravel token manager for password reset, account activation... and more. Laravel Cache Facade Based
README 文档
README
A tool for easy public token implementation in some common tasks: password reset, account activation, etc. In general, when need to send a token through mail (for example). We are developed with Laravel 5.x in mind.
Installation
Add in your composer.json:
{
"require": {
"malahierba-lab/token": "~1.0"
}
}
Then you need run the composer update command.
How Work
The tokens are save using Laravel Cache Facade, so you don't need a table in your database (unless you are using the database cache as driver), so... you don't need alter your current database, and tokens expire automatically without headaches :)
Use
Important: For documentation purposes, in the examples below, always we assume than you import the library into your namespace using use Malahierba\Token\Token;
You can generate a token for any model (Eloquent/Model) in your project. In this examples below we are using the User Model, but you can use the Model than you need.
1.- Make a Token Instance
//Get a Model Instance... in this case, a User instance.
$user = User::find(1);
// Create a password reset token instance
// 'password reset' is just a example... you can use the string than you want :)
// so.. if you want a token named 'my token type' just use it as second parameter. No predefined types.
$token = new Token($user, 'password reset');
//You can define the duration, in minutes, until the token expire. Default is 60.
//This example set 15 minutes to expire the token
$token = new Token($user, 'password reset', 15);
//Also you can define the number of chars for token. Default is 48
//This example set token length in 32 chars (and use the default minutes to expire)
$token = new Token($user, 'password reset', null, 32);
//This example set 15 minutes to expire the token and token length in 32 chars
$token = new Token($user, 'password reset', 15, 32);
2.- Get the Token string
$token_str = $token->get();
If no previous token exists (or previous token is expired), then you will get a new randomly generated string. If previous token exists (and is not expired yet) then you get that token.
3.- Check the Token
You can validate a token entered by an user or when come from url (for example if you mail a link for password reset with the token as parameter):
if ($token->check($string))
// code for token validated
4.- Delete the Token
When you don't need the token anymore (for example, your user already setup a new password in password reset lifecycle) you can delete it:
$token->delete();
The delete method no destroy the token instance, just delete the old token string. If you run $token->get() you will receive a new token for same user (and same type) because the instance is the same.
Licence
This project has MIT licence. For more information please read LICENCE file.
malahierba-lab/token 适用场景与选型建议
malahierba-lab/token 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 333 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「laravel」 「token」 「password reset」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 malahierba-lab/token 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 malahierba-lab/token 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 malahierba-lab/token 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A package for validating Google Cloud's JWT provided by webhooks
JSON Web Token Authentication for Laravel and Lumen
Laravel 5 - Repositories to the database layer
JSON Web Token Authentication for Laravel and Lumen
JSON Web Token Authentication for Laravel and Lumen
统计信息
- 总下载量: 333
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 29
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-24