diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0f7d23f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Release + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false diff --git a/.php_cs b/.php_cs index 32e3cbb..5a7b473 100644 --- a/.php_cs +++ b/.php_cs @@ -1,12 +1,11 @@ 配置文件位于 `config/autoload/ext-hashing.php`。 +> 配置文件位于 `config/autoload/hashing.php`。 ## 默认配置 @@ -48,7 +48,7 @@ return [ ]; ``` -你可以在 `config/autoload/ext-hashing.php` 配置文件中配置默认哈希驱动程序。目前支持三种驱动程序: Bcrypt 和 Argon2(Argon2i 和 Argon2id variants)。 +你可以在 `config/autoload/hashing.php` 配置文件中配置默认哈希驱动程序。目前支持三种驱动程序: Bcrypt 和 Argon2(Argon2i 和 Argon2id variants)。 > 注意:Argon2i 驱动程序需要 PHP 7.2.0 或更高版本,而 Argon2id 驱动程序则需要 PHP 7.3.0 或更高版本。 diff --git a/composer.json b/composer.json index 1cd9487..ab857df 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "hyperf", "hashing" ], - "description": "The unofficial Hyperf Hashing package.", + "description": "The Hyperf Hashing package.", "authors": [ { "name": "Eric Zhu", diff --git a/publish/ext-hashing.php b/publish/hashing.php similarity index 87% rename from publish/ext-hashing.php rename to publish/hashing.php index 5b587d6..f9adf67 100644 --- a/publish/ext-hashing.php +++ b/publish/hashing.php @@ -1,9 +1,14 @@ [ 'class' => \HyperfExt\Hashing\Driver\BcryptDriver::class, - 'options'=> [ + 'options' => [ 'rounds' => env('BCRYPT_ROUNDS', 10), ], ], @@ -49,7 +54,7 @@ 'argon2i' => [ 'class' => \HyperfExt\Hashing\Driver\Argon2IDriver::class, - 'options'=> [ + 'options' => [ 'memory' => 1024, 'threads' => 2, 'time' => 2, @@ -58,12 +63,11 @@ 'argon2id' => [ 'class' => \HyperfExt\Hashing\Driver\Argon2IdDriver::class, - 'options'=> [ + 'options' => [ 'memory' => 1024, 'threads' => 2, 'time' => 2, ], ], ], - ]; diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 10fdbf8..0f94af8 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -2,12 +2,11 @@ declare(strict_types=1); /** - * This file is part of Hyperf. + * This file is part of hyperf-ext/hashing. * - * @link https://www.hyperf.io - * @document https://doc.hyperf.io - * @contact group@hyperf.io - * @license https://github.com/hyperf/hyperf/blob/master/LICENSE + * @link https://github.com/hyperf-ext/hashing + * @contact eric@zhu.email + * @license https://github.com/hyperf-ext/hashing/blob/master/LICENSE */ namespace HyperfExt\Hashing; @@ -32,8 +31,8 @@ public function __invoke(): array [ 'id' => 'config', 'description' => 'The config for HyperfExt\\Hashing.', - 'source' => __DIR__ . '/../publish/ext-hashing.php', - 'destination' => BASE_PATH . '/config/autoload/ext-hashing.php', + 'source' => __DIR__ . '/../publish/hashing.php', + 'destination' => BASE_PATH . '/config/autoload/hashing.php', ], ], ]; diff --git a/src/Contract/DriverInterface.php b/src/Contract/DriverInterface.php index b48eaef..90e6c32 100644 --- a/src/Contract/DriverInterface.php +++ b/src/Contract/DriverInterface.php @@ -1,48 +1,34 @@ algorithm(), [ 'memory_cost' => $this->memory($options), - 'time_cost' => $this->time($options), - 'threads' => $this->threads($options), + 'time_cost' => $this->time($options), + 'threads' => $this->threads($options), ]); if ($hash === false) { @@ -77,25 +74,9 @@ public function make(string $value, array $options = []): string return $hash; } - /** - * Get the algorithm that should be used for hashing. - * - * @return int - */ - protected function algorithm() - { - return PASSWORD_ARGON2I; - } - /** * Check the given plain value against a hash. * - * @param string $value - * @param string $hashedValue - * @param array $options - * - * @return bool - * * @throws \RuntimeException */ public function check(string $value, string $hashedValue, array $options = []): bool @@ -109,26 +90,19 @@ public function check(string $value, string $hashedValue, array $options = []): /** * Check if the given hash has been hashed using the given options. - * - * @param string $hashedValue - * @param array $options - * - * @return bool */ public function needsRehash(string $hashedValue, array $options = []): bool { return password_needs_rehash($hashedValue, $this->algorithm(), [ 'memory_cost' => $this->memory($options), - 'time_cost' => $this->time($options), - 'threads' => $this->threads($options), + 'time_cost' => $this->time($options), + 'threads' => $this->threads($options), ]); } /** * Set the default password memory factor. * - * @param int $memory - * * @return $this */ public function setMemory(int $memory): self @@ -141,8 +115,6 @@ public function setMemory(int $memory): self /** * Set the default password timing factor. * - * @param int $time - * * @return $this */ public function setTime(int $time): self @@ -155,8 +127,6 @@ public function setTime(int $time): self /** * Set the default password threads factor. * - * @param int $threads - * * @return $this */ public function setThreads(int $threads): self @@ -167,12 +137,18 @@ public function setThreads(int $threads): self } /** - * Extract the memory cost value from the options array. - * - * @param array $options + * Get the algorithm that should be used for hashing. * * @return int */ + protected function algorithm() + { + return PASSWORD_ARGON2I; + } + + /** + * Extract the memory cost value from the options array. + */ protected function memory(array $options): int { return $options['memory'] ?? $this->memory; @@ -180,10 +156,6 @@ protected function memory(array $options): int /** * Extract the time cost value from the options array. - * - * @param array $options - * - * @return int */ protected function time(array $options): int { @@ -192,10 +164,6 @@ protected function time(array $options): int /** * Extract the threads value from the options array. - * - * @param array $options - * - * @return int */ protected function threads(array $options): int { diff --git a/src/Driver/Argon2IdDriver.php b/src/Driver/Argon2IdDriver.php index fd615db..c76da74 100644 --- a/src/Driver/Argon2IdDriver.php +++ b/src/Driver/Argon2IdDriver.php @@ -1,7 +1,13 @@ needsRehash($hashedValue. $options); + return static::getDriver($driverName)->needsRehash($hashedValue . $options); } } diff --git a/src/HashManager.php b/src/HashManager.php index 5e76933..3b7b591 100644 --- a/src/HashManager.php +++ b/src/HashManager.php @@ -1,7 +1,13 @@ drivers[$name]; } - $name = $name ?: $this->config->get('ext-hashing.default', 'bcrypt'); + $name = $name ?: $this->config->get('hashing.default', 'bcrypt'); - $config = $this->config->get("ext-hashing.driver.{$name}"); + $config = $this->config->get("hashing.driver.{$name}"); if (empty($config) or empty($config['class'])) { throw new InvalidArgumentException(sprintf('The hashing driver config %s is invalid.', $name)); } diff --git a/tests/HashTest.php b/tests/HashTest.php index 519eb94..ade4851 100644 --- a/tests/HashTest.php +++ b/tests/HashTest.php @@ -1,7 +1,13 @@ make('password'); $this->assertNotSame('password', $value); $this->assertTrue($hasher->check('password', $value)); @@ -29,11 +35,11 @@ public function testBasicBcryptHashing() public function testBasicArgon2iHashing() { - if (!defined('PASSWORD_ARGON2I')) { + if (! defined('PASSWORD_ARGON2I')) { $this->markTestSkipped('PHP not compiled with Argon2i hashing support.'); } - $hasher = new Argon2IDriver; + $hasher = new Argon2IDriver(); $value = $hasher->make('password'); $this->assertNotSame('password', $value); $this->assertTrue($hasher->check('password', $value)); @@ -44,11 +50,11 @@ public function testBasicArgon2iHashing() public function testBasicArgon2idHashing() { - if (!defined('PASSWORD_ARGON2ID')) { + if (! defined('PASSWORD_ARGON2ID')) { $this->markTestSkipped('PHP not compiled with Argon2id hashing support.'); } - $hasher = new Argon2IdDriver; + $hasher = new Argon2IdDriver(); $value = $hasher->make('password'); $this->assertNotSame('password', $value); $this->assertTrue($hasher->check('password', $value)); @@ -64,7 +70,7 @@ public function testBasicBcryptVerification() { $this->expectException(RuntimeException::class); - if (!defined('PASSWORD_ARGON2I')) { + if (! defined('PASSWORD_ARGON2I')) { $this->markTestSkipped('PHP not compiled with Argon2i hashing support.'); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b4f1239..9d1d4bd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,14 +1,11 @@