commit
2e0534b729
20
README.md
20
README.md
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
A simple implementation of zxcvbn for Laravel 5. This package allows you to access "zxcvbn-related" data on a passphrase in the application and also to use zxcvbn as a standard validator.
|
A simple implementation of zxcvbn for Laravel 5. This package allows you to access "zxcvbn-related" data on a passphrase in the application and also to use zxcvbn as a standard validator.
|
||||||
|
|
||||||
Uses [Zxcvbn-PHP](https://github.com/bjeavons/zxcvbn-php) by [@bjeavons](https://github.com/bjeavons), which in turn is inspired by [zxcvbn](https://github.com/dropbox/zxcvbn) by [@dropbox](https://github.com/dropbox).
|
Uses [Zxcvbn-PHP](https://github.com/mkopinsky/zxcvbn-php) by [@mkopinsky](https://github.com/mkopinsky) (originally by [@bjeavons](https://github.com/bjeavons)), which in turn is inspired by [zxcvbn](https://github.com/dropbox/zxcvbn) by [@dropbox](https://github.com/dropbox).
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
|
@ -54,17 +54,19 @@ class MyClass extends MyOtherClass
|
||||||
$zxcvbn = Zxcvbn::passwordStrength('password');
|
$zxcvbn = Zxcvbn::passwordStrength('password');
|
||||||
dd($zxcvbn);
|
dd($zxcvbn);
|
||||||
|
|
||||||
// array:6 [▼
|
// array:9 [
|
||||||
// "crack_time" => 5.0E-5
|
// "password" => "password"
|
||||||
// "calc_time" => 0.12961101531982
|
// "guesses" => 3
|
||||||
// "password" => "password"
|
// "guesses_log10" => 0.47712125471966
|
||||||
// "entropy" => 0.0
|
// "sequence" => array:1 []
|
||||||
// "match_sequence" => array:1 []
|
// "crack_times_seconds" => array:4 []
|
||||||
// "score" => 0
|
// "crack_times_display" => array:4 []
|
||||||
|
// "score" => 0
|
||||||
|
// "feedback" => array:2 []
|
||||||
|
// "calc_time" => 0.042769908905029
|
||||||
// ]
|
// ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Play around with different passwords and phrases, the results may surprise you. Check out [Zxcvbn-PHP](https://github.com/bjeavons/zxcvbn-php) for more uses and examples.
|
Play around with different passwords and phrases, the results may surprise you. Check out [Zxcvbn-PHP](https://github.com/bjeavons/zxcvbn-php) for more uses and examples.
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php" : ">=7.1.3",
|
"php" : ">=7.1.3",
|
||||||
"illuminate/support": "^5.8",
|
"illuminate/support": "^5.8",
|
||||||
"bjeavons/zxcvbn-php": "0.4.0"
|
"mkopinsky/zxcvbn-php": "^4.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit" : "~7.0",
|
"phpunit/phpunit" : "~7.0",
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ class ZxcvbnServiceProvider extends ServiceProvider
|
||||||
$zxcvbn = new ZxcvbnPhp();
|
$zxcvbn = new ZxcvbnPhp();
|
||||||
$zxcvbn = $zxcvbn->passwordStrength($value, [$username, $email]);
|
$zxcvbn = $zxcvbn->passwordStrength($value, [$username, $email]);
|
||||||
|
|
||||||
if (isset($zxcvbn['match_sequence'][0])) {
|
if (isset($zxcvbn['sequence'][0])) {
|
||||||
$dictionary = $zxcvbn['match_sequence'][0];
|
$dictionary = $zxcvbn['sequence'][0];
|
||||||
if (isset($dictionary->dictionaryName)) {
|
if (isset($dictionary->dictionaryName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +74,7 @@ class ZxcvbnServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->bind('zxcvbn', function($app) {
|
$this->app->bind('zxcvbn', function() {
|
||||||
return new ZxcvbnPhp();
|
return new ZxcvbnPhp();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,17 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
||||||
*/
|
*/
|
||||||
public function test_zxcvbn_basics()
|
public function test_zxcvbn_basics()
|
||||||
{
|
{
|
||||||
|
$zxcvbn = Zxcvbn::passwordStrength('password');
|
||||||
|
|
||||||
$testVar1 = Zxcvbn::passwordStrength('test');
|
$testVar1 = Zxcvbn::passwordStrength('test');
|
||||||
|
|
||||||
// Check keys
|
// Check keys
|
||||||
$this->assertArrayHasKey('score', $testVar1);
|
$this->assertArrayHasKey('score', $testVar1);
|
||||||
$this->assertArrayHasKey('match_sequence', $testVar1);
|
$this->assertArrayHasKey('sequence', $testVar1);
|
||||||
$this->assertArrayHasKey('entropy', $testVar1);
|
$this->assertArrayHasKey('crack_times_seconds', $testVar1);
|
||||||
$this->assertArrayHasKey('password', $testVar1);
|
$this->assertArrayHasKey('crack_times_display', $testVar1);
|
||||||
$this->assertArrayHasKey('calc_time', $testVar1);
|
$this->assertArrayHasKey('calc_time', $testVar1);
|
||||||
$this->assertArrayHasKey('crack_time', $testVar1);
|
$this->assertArrayHasKey('guesses', $testVar1);
|
||||||
|
|
||||||
// Check score-value
|
// Check score-value
|
||||||
$this->assertEquals(0, $testVar1['score']);
|
$this->assertEquals(0, $testVar1['score']);
|
||||||
|
|
@ -57,7 +59,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
||||||
$testVar4 = Zxcvbn::passwordStrength('7E6k9axB*gwGHa&aZTohmD9Wr&NVs[b4'); //<-- 32
|
$testVar4 = Zxcvbn::passwordStrength('7E6k9axB*gwGHa&aZTohmD9Wr&NVs[b4'); //<-- 32
|
||||||
|
|
||||||
// Check score-value
|
// Check score-value
|
||||||
$this->assertEquals(1, $testVar2['score']);
|
$this->assertEquals(2, $testVar2['score']);
|
||||||
$this->assertEquals(4, $testVar3['score']);
|
$this->assertEquals(4, $testVar3['score']);
|
||||||
$this->assertEquals(4, $testVar4['score']);
|
$this->assertEquals(4, $testVar4['score']);
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +108,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'));
|
$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)
|
private function validate_without_message_min($password, $min)
|
||||||
{
|
{
|
||||||
$data = ['password' => $password];
|
$data = ['password' => $password];
|
||||||
|
|
@ -116,6 +119,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
||||||
return $validator->passes();
|
return $validator->passes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @note validation helper */
|
||||||
private function validate_with_message_min($password, $min, $message)
|
private function validate_with_message_min($password, $min, $message)
|
||||||
{
|
{
|
||||||
$data = ['password' => $password];
|
$data = ['password' => $password];
|
||||||
|
|
@ -129,6 +133,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
||||||
return $errors->first('password');
|
return $errors->first('password');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @note validation helper */
|
||||||
private function validate_without_message_dictionary($password, $email, $username)
|
private function validate_without_message_dictionary($password, $email, $username)
|
||||||
{
|
{
|
||||||
$data = ['password' => $password];
|
$data = ['password' => $password];
|
||||||
|
|
@ -139,6 +144,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
||||||
return $validator->passes();
|
return $validator->passes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @note validation helper */
|
||||||
private function validate_with_message_dictionary($password, $email, $username, $message)
|
private function validate_with_message_dictionary($password, $email, $username, $message)
|
||||||
{
|
{
|
||||||
$data = ['password' => $password];
|
$data = ['password' => $password];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue