rancoud/crypt
Composer 安装命令:
composer require rancoud/crypt
包简介
Crypt package
README 文档
README
Crypt using Argon2id by default with Argon2i and bcrypt in fallback.
Installation
composer require rancoud/crypt
How to use it?
use Rancoud\Crypt\Crypt; $password = 'my_password'; $hash = Crypt::hash($password); $result = Crypt::verify($password, $hash); // use only Argon2i Crypt::useArgon2i(); // use only bcrypt Crypt::useBcrypt();
Crypt
Main functions
Hashs the password according to the selected algorithm.
public static function hash(string $password): string
Checks whether the hash needs to be rehash to match the selected algorithm and options.
public static function needsRehash(string $hash): bool
Checks if password and hash match.
public static function verify(string $password, string $hash): bool
Algorithms
Returns current algorithm.
Possible values are argon2id, argon2i or 2y.
public static function getCurrentAlgo(): string
Sets the algorithm to argon2id.
public static function useArgon2id(): void
Sets the algorithm to argon2i.
public static function useArgon2i(): void
Sets the algorithm to 2y (bcrypt).
public static function useBcrypt(): void
Options
Sets memory cost for argon2id and argon2i.
Must be equal or greater than 8.
public static function setOptionArgon2iMemoryCost(int $bytes): void
Sets number of threads for argon2id and argon2i.
Must be equal or greater than 1.
public static function setOptionArgon2iThreads(int $threads): void
Sets time cost for argon2id and argon2i.
Must be equal or greater than 1.
public static function setOptionArgon2iTimeCost(int $time): void
Sets rounds cost for 2y (bcrypt).
Must be between 4 and 31.
public static function setOptionBcryptCost(int $rounds): void
Returns options for argon2id and argon2i.
public static function getOptionsArgon2i(): array
Returns options for 2y (bcrypt).
public static function getOptionsBcrypt(): array
Random string
Returns a fixed-size string containing random characters from the preselection.
The default character pool is !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~.
public static function getRandomString(int $length = 64, ?string $characters = null): string
Returns the character pool.
public static function getCharactersForRandomString(): string
Sets the character pool.
public static function setCharactersForRandomString(string $characters): void
How to Dev
composer ci for php-cs-fixer and phpunit and coverage
composer lint for php-cs-fixer
composer test for phpunit and coverage
rancoud/crypt 适用场景与选型建议
rancoud/crypt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.89k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rancoud/crypt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rancoud/crypt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-04