{"id":20732307,"url":"https://github.com/zhuchunshu/hyperf-hashing","last_synced_at":"2025-10-11T09:13:07.650Z","repository":{"id":57091021,"uuid":"388020033","full_name":"zhuchunshu/hyperf-hashing","owner":"zhuchunshu","description":null,"archived":false,"fork":false,"pushed_at":"2023-07-31T04:17:51.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-23T00:25:20.785Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhuchunshu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-21T06:41:43.000Z","updated_at":"2022-12-08T14:23:33.000Z","dependencies_parsed_at":"2025-01-18T00:40:50.534Z","dependency_job_id":null,"html_url":"https://github.com/zhuchunshu/hyperf-hashing","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"1c9410ce7b6f832e9272fda5c53565012c567de6"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zhuchunshu/hyperf-hashing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuchunshu%2Fhyperf-hashing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuchunshu%2Fhyperf-hashing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuchunshu%2Fhyperf-hashing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuchunshu%2Fhyperf-hashing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhuchunshu","download_url":"https://codeload.github.com/zhuchunshu/hyperf-hashing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhuchunshu%2Fhyperf-hashing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006756,"owners_count":26084177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T05:18:53.968Z","updated_at":"2025-10-11T09:13:07.612Z","avatar_url":"https://github.com/zhuchunshu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hyperf 哈希组件\n\n该组件为存储用户密码提供了安全的 Bcrypt 和 Argon2 哈希加密方式。\n\n\u003e 移植自 [illuminate/hashing](https://github.com/illuminate/hashing )。\n\n## 安装\n\n```shell script\ncomposer require zhuchunshu/hyperf-hashing\n```\n\n## 发布配置\n\n```shell script\nphp bin/hyperf.php vendor:publish zhuchunshu/hyperf-hashing\n```\n\n\u003e 配置文件位于 `config/autoload/hashing.php`。\n\n## 默认配置\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nreturn [\n    'default' =\u003e 'bcrypt',\n    'driver' =\u003e [\n        'bcrypt' =\u003e [\n            'class' =\u003e \\HyperfExt\\Hashing\\Driver\\BcryptDriver::class,\n            'rounds' =\u003e env('BCRYPT_ROUNDS', 10),\n        ],\n        'argon' =\u003e [\n            'class' =\u003e \\HyperfExt\\Hashing\\Driver\\Argon2IDriver::class,\n            'memory' =\u003e 1024,\n            'threads' =\u003e 2,\n            'time' =\u003e 2,\n        ],\n        'argon2id' =\u003e [\n            'class' =\u003e \\HyperfExt\\Hashing\\Driver\\Argon2IdDriver::class,\n            'memory' =\u003e 1024,\n            'threads' =\u003e 2,\n            'time' =\u003e 2,\n        ],\n    ],\n];\n```\n\n你可以在 `config/autoload/hashing.php` 配置文件中配置默认哈希驱动程序。目前支持三种驱动程序： Bcrypt 和 Argon2（Argon2i 和 Argon2id variants）。\n\n\u003e 注意：Argon2i 驱动程序需要 PHP 7.2.0 或更高版本，而 Argon2id 驱动程序则需要 PHP 7.3.0 或更高版本。\n\n## 使用\n\n你可以通过 `\\HyperfExt\\Hashing\\Hash` 类来加密你的密码：\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Http\\Controller;\n\nuse Hyperf\\HttpServer\\Request;\nuse HyperfExt\\Hashing\\Hash;\n\nclass UpdatePasswordController\n{\n    public function update(Request $request)\n    {\n        // ……\n\n        $user-\u003efill([\n            'password' =\u003e Hash::make($request-\u003einput('new_password'))\n        ])-\u003esave();\n    }\n}\n```\n\n### 调整 Bcrypt 加密系数\n\n如果使用 Bcrypt 算法，你可以在 `make` 方法中使用 `rounds` 选项来配置该算法的加密系数。然而，对大多数应用程序来说，默认值就足够了：\n\n```php\n$hashed = Hash::make('password', [\n    'rounds' =\u003e 12\n]);\n```\n\n### 调整 Argon2 加密系数\n\n如果使用 Argon2 算法，你可以在 `make` 方法中使用 `memory`，`time` 和 `threads` 选项来配置该算法的加密系数。然后，对大多数应用程序来说，默认值就足够了：\n\n```php\n$hashed = Hash::make('password', [\n    'memory' =\u003e 1024,\n    'time' =\u003e 2,\n    'threads' =\u003e 2,\n]);\n```\n\n\u003e 有关这些选项的更多信息，请查阅 [PHP 官方文档](https://secure.php.net/manual/en/function.password-hash.php )。\n\n### 密码哈希验证\n\n`check` 方法能为您验证一段给定的未加密字符串与给定的哈希值是否一致：\n\n```php\nif (Hash::check('plain-text', $hashedPassword)) {\n    // 密码匹配…\n}\n```\n\n### 检查密码是否需要重新哈希\n\n`needsRehash` 方法可以为您检查当哈希的加密系数改变时，您的密码是否被新的加密系数重新加密过：\n\n```php\nif (Hash::needsRehash($hashed)) {\n    $hashed = Hash::make('plain-text');\n}\n```\n\n### 使用指定驱动\n\n```php\n$hasher = Hash::getDriver('argon2i');\n$hasher-\u003emake('plain-text');\n```\n\n### 使用自定义哈希类\n\n实现 `\\HyperfExt\\Hashing\\Contract\\DriverInterface` 接口，并参照配置文件中的其他算法进行配置。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuchunshu%2Fhyperf-hashing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhuchunshu%2Fhyperf-hashing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhuchunshu%2Fhyperf-hashing/lists"}