crazedsanity/authtoken
Composer 安装命令:
composer require crazedsanity/authtoken
包简介
Library for creating and manipulating authentication/authorization tokens, for things like password hashes and API keys.
README 文档
README
This system is built to handle either authentication or authorization, or both. A common usage for this system is for storing temporary tokens for changing passwords: a user requests that their password get changed, so they are sent an email with a link containing some weird complicated hash. This is the system that handles the logic of creating the tokens and storing them in the database, along with handling automatic expiration.
What Are Tokens For?
Imagine you've got a web application, and there's authentication involved. You're going to create a "simple" system wherein a user can click something and generate a "lost password" request. Since you want to be user-friend and security-conscious, your system generates an email with a link for them to follow. With CS Auth Token, you can create one that:
- only works for the specified user's account
- expires after a single (successful) use
- expires after a given period of time
- is cryptographically secure
How Do I Use It?
I could explain it, but really, it's easier just to show you:
$x = new cs_authToken($db, $uidOfUser); $hash = $x->create_token($email);
The email might look something like:
Hello {friendlyName},
To reset your password, please click this link:
http://www.cs.local/lost?hash={hash}?key={email}
The code to handle verification looks like:
$x = new cs_authToken($db); $authData = $x->authenticate_token($hash, $key); if($authData['result'] == true) { //authenticated! use 'stored_value' to help in resetting their password $myData = $authData['stored_value']; }
Expiration Possibilities
Currently, there are a number of ways that a token can be expired:
- a given number of maximum uses (e.g. 1 use)
- an specific date of expiration (e.g. 15 minutes from when it was created)
- a limited number of uses + a specific expiration date (e.g. 1 use in the next 15 minutes)
- no specific expiration (the token will never be automatically removed)
Some things these tokens could be used for (they're just ideas):
- token API calls
- 1000 uses until token expires
- 30 days until token expires
- limit of 1000 uses during the next 30 days
- sessions:
- 1000 page views before need to login again
- must expire before a certain date
- 1000 page views OR until a certain date (whichever comes first)
- licensing (requires something to keep token from being destroyed, depending upon implementation)
- 5 allowed licenses for 1 year
- unlimited users for 1 year
- 5 users, no expiration
- unlimited users for 1 year
crazedsanity/authtoken 适用场景与选型建议
crazedsanity/authtoken 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 171 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 crazedsanity/authtoken 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 crazedsanity/authtoken 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 171
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-21