From fc3b58165b0e6bfd16a91e574bd16eff307f56fd Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Thu, 20 Jun 2019 14:27:17 +0200 Subject: [PATCH] Ported to use mkopinsky/zxcvbn-php and minor tweaks. --- composer.json | 2 +- src/ZxcvbnServiceProvider.php | 4 ++-- tests/ZxcvbnTest.php | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index f161f20..07144fb 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "php" : ">=7.1.3", "illuminate/support": "^5.8", - "bjeavons/zxcvbn-php": "0.4.0" + "mkopinsky/zxcvbn-php": "^4.4" }, "require-dev": { "phpunit/phpunit" : "~7.0", diff --git a/src/ZxcvbnServiceProvider.php b/src/ZxcvbnServiceProvider.php index f045b4c..c2c059d 100644 --- a/src/ZxcvbnServiceProvider.php +++ b/src/ZxcvbnServiceProvider.php @@ -50,8 +50,8 @@ class ZxcvbnServiceProvider extends ServiceProvider $zxcvbn = new ZxcvbnPhp(); $zxcvbn = $zxcvbn->passwordStrength($value, [$username, $email]); - if (isset($zxcvbn['match_sequence'][0])) { - $dictionary = $zxcvbn['match_sequence'][0]; + if (isset($zxcvbn['sequence'][0])) { + $dictionary = $zxcvbn['sequence'][0]; if (isset($dictionary->dictionaryName)) { return false; } diff --git a/tests/ZxcvbnTest.php b/tests/ZxcvbnTest.php index 8a11ada..db529bf 100644 --- a/tests/ZxcvbnTest.php +++ b/tests/ZxcvbnTest.php @@ -38,15 +38,18 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { */ public function test_zxcvbn_basics() { + $zxcvbn = Zxcvbn::passwordStrength('password'); + dd($zxcvbn); + $testVar1 = Zxcvbn::passwordStrength('test'); // Check keys $this->assertArrayHasKey('score', $testVar1); - $this->assertArrayHasKey('match_sequence', $testVar1); - $this->assertArrayHasKey('entropy', $testVar1); - $this->assertArrayHasKey('password', $testVar1); + $this->assertArrayHasKey('sequence', $testVar1); + $this->assertArrayHasKey('crack_times_seconds', $testVar1); + $this->assertArrayHasKey('crack_times_display', $testVar1); $this->assertArrayHasKey('calc_time', $testVar1); - $this->assertArrayHasKey('crack_time', $testVar1); + $this->assertArrayHasKey('guesses', $testVar1); // Check score-value $this->assertEquals(0, $testVar1['score']); @@ -57,7 +60,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { $testVar4 = Zxcvbn::passwordStrength('7E6k9axB*gwGHa&aZTohmD9Wr&NVs[b4'); //<-- 32 // Check score-value - $this->assertEquals(1, $testVar2['score']); + $this->assertEquals(2, $testVar2['score']); $this->assertEquals(4, $testVar3['score']); $this->assertEquals(4, $testVar4['score']); } @@ -106,6 +109,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { $this->assertEquals('Just a message', $this->validate_with_message_dictionary('test', 'test@test.com', 'test', 'Just a message')); } + /** @note validation helper */ private function validate_without_message_min($password, $min) { $data = ['password' => $password]; @@ -116,6 +120,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { return $validator->passes(); } + /** @note validation helper */ private function validate_with_message_min($password, $min, $message) { $data = ['password' => $password]; @@ -129,6 +134,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { return $errors->first('password'); } + /** @note validation helper */ private function validate_without_message_dictionary($password, $email, $username) { $data = ['password' => $password]; @@ -139,6 +145,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase { return $validator->passes(); } + /** @note validation helper */ private function validate_with_message_dictionary($password, $email, $username, $message) { $data = ['password' => $password];