{"id":22678286,"url":"https://github.com/hyperf-ext/hashing","last_synced_at":"2025-07-24T08:34:23.052Z","repository":{"id":47930275,"uuid":"292236347","full_name":"hyperf-ext/hashing","owner":"hyperf-ext","description":"The Hyperf Hashing package.","archived":false,"fork":false,"pushed_at":"2024-02-16T16:05:23.000Z","size":27,"stargazers_count":14,"open_issues_count":4,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-20T01:50:18.414Z","etag":null,"topics":["hashing","hyperf","php"],"latest_commit_sha":null,"homepage":"","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/hyperf-ext.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":"2020-09-02T09:19:05.000Z","updated_at":"2024-12-16T06:00:51.000Z","dependencies_parsed_at":"2024-06-18T18:36:38.469Z","dependency_job_id":"f23e5562-9789-470d-a770-a01733d7cd1a","html_url":"https://github.com/hyperf-ext/hashing","commit_stats":{"total_commits":8,"total_committers":3,"mean_commits":"2.6666666666666665","dds":0.5,"last_synced_commit":"e3399ebcaa8242e36bae988533e7acdfd4a73c94"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/hyperf-ext/hashing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhashing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhashing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhashing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhashing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperf-ext","download_url":"https://codeload.github.com/hyperf-ext/hashing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf-ext%2Fhashing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266815195,"owners_count":23988560,"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-07-24T02:00:09.469Z","response_time":99,"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":["hashing","hyperf","php"],"created_at":"2024-12-09T18:14:40.936Z","updated_at":"2025-07-24T08:34:22.431Z","avatar_url":"https://github.com/hyperf-ext.png","language":"PHP","readme":"# Hyperf 哈希组件\n\n该组件为存储用户密码提供了安全的 Bcrypt 和 Argon2 哈希加密方式。\n\n\u003e 移植自 [illuminate/hashing](https://github.com/illuminate/hashing )。\n\n## 安装\n\n```shell script\ncomposer require hyperf-ext/hashing\n```\n\n## 发布配置\n\n```shell script\nphp bin/hyperf.php vendor:publish hyperf-ext/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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-ext%2Fhashing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperf-ext%2Fhashing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf-ext%2Fhashing/lists"}