Compare commits

...

13 Commits

Author SHA1 Message Date
Marcus Olsson 1ea671c7fe
Laravel 9 support (#19)
* Add Laravel 9 requirement

* Remove scrutinizer test

* Create test.yml

* Fix directory name

* Fix issue on older PHP-ver
2022-02-08 17:33:29 +01:00
Marcus Olsson 7032f90820
Update for PHP 8 (#17)
* Update for PHP 8

* Switch to bjeavons/zxcvbn-php-library
2020-12-06 11:08:14 +01:00
Marcus Olsson 4fff615d5f
Merge pull request #16 from kblais/laravel-8-update
Laravel 8 compatibility
2020-09-09 12:50:13 +02:00
Killian Blais 52da9e5fa2 Laravel 8 compatibility 2020-09-09 12:35:34 +02:00
Marcus Olsson 235147e935
Merge pull request #15 from olssonm/dev
Laravel 7 update.
2020-03-11 15:04:35 +01:00
Marcus Olsson b494aa89f9
Laravel 7 update. 2020-03-11 15:00:28 +01:00
Marcus Olsson 5128d310eb
Updated readme.md 2019-09-17 07:32:24 +02:00
Marcus Olsson 7cf2acd39f
Merge pull request #14 from olssonm/dev
Laravel 6 compatibility update.
2019-09-17 07:29:48 +02:00
Marcus Olsson 8df76e3c62
Laravel 6 compatability update. 2019-09-17 07:26:05 +02:00
Marcus Olsson 2e0534b729
Merge pull request #13 from olssonm/dev
Update for #12
2019-06-20 14:37:15 +02:00
Marcus Olsson 341a596189
Removed debug code, cleanup. 2019-06-20 14:30:14 +02:00
Marcus Olsson e643e830f7
Readme update. 2019-06-20 14:27:24 +02:00
Marcus Olsson fc3b58165b
Ported to use mkopinsky/zxcvbn-php and minor tweaks. 2019-06-20 14:27:17 +02:00
9 changed files with 91 additions and 80 deletions

45
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,45 @@
name: Laravel automated tests
on:
push:
branches: ['master', 'feature/**']
pull_request:
branches: ['master']
jobs:
php-tests:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- php: 8.1
illuminate: ^9.0
- php: 8.1
illuminate: ^8.0
- php: 8.0
illuminate: ^8.0
- php: 7.4
illuminate: ^7.0
- php: 7.3
illuminate: ^7.0
name: PHP ${{ matrix.php }} - Illuminate ${{ matrix.illuminate }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Update composer
run: composer self-update --2
- name: Install dependencies
run: composer require "illuminate/support:${{ matrix.illuminate }}" --no-interaction --no-progress --no-suggest
- name: Execute tests
run: composer test

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/vendor /vendor
composer.lock composer.lock
/.phpunit.result.cache

View File

@ -1,18 +0,0 @@
filter:
excluded_paths: [tests/*]
checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

View File

@ -1,17 +0,0 @@
language: php
sudo: false
before_script:
- travis_retry composer self-update
- travis_retry composer require "illuminate/support:${ILLUMINATE_VERSION}"
script:
- composer test
matrix:
include:
- php: 7.1
env: ILLUMINATE_VERSION=5.8.*
- php: 7.2
env: ILLUMINATE_VERSION=5.8.*

View File

@ -1,6 +1,6 @@
# The MIT License (MIT) # The MIT License (MIT)
Copyright (c) 2018 Marcus Olsson <contact@marcusolsson.me> Copyright (c) 2020 Marcus Olsson <contact@marcusolsson.me>
> Permission is hereby granted, free of charge, to any person obtaining a copy > Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal > of this software and associated documentation files (the "Software"), to deal

View File

@ -1,16 +1,15 @@
# Zxcvbn for Laravel 5 # Zxcvbn for Laravel
[![Latest Version on Packagist][ico-version]][link-packagist] [![Latest Version on Packagist][ico-version]][link-packagist]
[![Total downloads][ico-downloads]][link-packagist] [![Total downloads][ico-downloads]][link-packagist]
[![Software License][ico-license]](LICENSE.md) [![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis] [![Build Status](https://img.shields.io/github/workflow/status/olssonm/laravel-zxcvbn/Laravel%20automated%20tests?style=flat-square)](https://github.com/olssonm/ampersand/actions/workflows/test.yml)
[![Scrutinizer Score][ico-scrutinizer]][link-scrutinizer]
![zxcvbn](https://user-images.githubusercontent.com/907114/41193108-747d9b50-6c08-11e8-8f9c-57874f52fa9b.png) ![zxcvbn](https://user-images.githubusercontent.com/907114/41193108-747d9b50-6c08-11e8-8f9c-57874f52fa9b.png)
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. 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/bjeavons/zxcvbn-php) by [@bjeavons](https://github.com/bjeavons) and [@mkopinsky](https://github.com/mkopinsky), which in turn is inspired by [zxcvbn](https://github.com/dropbox/zxcvbn) by [@dropbox](https://github.com/dropbox).
## Install ## Install
@ -20,14 +19,6 @@ Via Composer
$ composer require olssonm/l5-zxcvbn $ composer require olssonm/l5-zxcvbn
``` ```
Add the package to your providers array (will be added automatically in Laravel 5.5+):
```php
'providers' => [
Olssonm\Zxcvbn\ZxcvbnServiceProvider::class,
]
```
If you wish to have the ability to use `Zxcvbn` via dependency injection, or just have a quick way to access the class add an alias to the facades: If you wish to have the ability to use `Zxcvbn` via dependency injection, or just have a quick way to access the class add an alias to the facades:
```php ```php
@ -54,17 +45,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.
@ -116,7 +109,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
'email' => 'trash@thedumpster.com' 'email' => 'trash@thedumpster.com'
]; ];
$validator = Validator::make($password, [ $validator = Validator::make($password, [
'password' => 'zxcvbn_dictionary:' . $data['username'] . ',' . $data['email'] . '|required', 'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $data['username'], $data['email'])
]); ]);
dd($validator->passes()); dd($validator->passes());
@ -131,7 +124,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
'email' => 'mycomplicatedphrase@thedumpster.com' 'email' => 'mycomplicatedphrase@thedumpster.com'
]; ];
$validator = Validator::make($password, [ $validator = Validator::make($password, [
'password' => 'zxcvbn_dictionary:' . $data['username'] . ',' . $data['email'] . '|required', 'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $data['username'], $data['email'])
]); ]);
dd($validator->passes()); dd($validator->passes());
@ -154,7 +147,7 @@ $ phpunit
The MIT License (MIT). Please see the [License File](LICENSE.md) for more information. The MIT License (MIT). Please see the [License File](LICENSE.md) for more information.
© 2018 [Marcus Olsson](https://marcusolsson.me). © 2020 [Marcus Olsson](https://marcusolsson.me).
[ico-version]: https://img.shields.io/packagist/v/olssonm/l5-zxcvbn.svg?style=flat-square [ico-version]: https://img.shields.io/packagist/v/olssonm/l5-zxcvbn.svg?style=flat-square
@ -162,12 +155,12 @@ The MIT License (MIT). Please see the [License File](LICENSE.md) for more inform
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/olssonm/l5-zxcvbn/master.svg?style=flat-square [ico-travis]: https://img.shields.io/travis/olssonm/laravel-zxcvbn/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/olssonm/l5-zxcvbn.svg?style=flat-square [ico-scrutinizer]: https://img.shields.io/scrutinizer/g/olssonm/l5-zxcvbn.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/olssonm/l5-zxcvbn [link-packagist]: https://packagist.org/packages/olssonm/l5-zxcvbn
[link-travis]: https://travis-ci.org/olssonm/l5-zxcvbn [link-travis]: https://travis-ci.org/olssonm/laravel-zxcvbn
[link-scrutinizer]: https://scrutinizer-ci.com/g/olssonm/l5-zxcvbn [link-scrutinizer]: https://scrutinizer-ci.com/g/olssonm/l5-zxcvbn

View File

@ -1,6 +1,6 @@
{ {
"name": "olssonm/l5-zxcvbn", "name": "olssonm/laravel-zxcvbn",
"description": "Implementation of the zxcvbn project by @dropbox for Laravel 5. Uses zxcvbn-php by @bjeavons.", "description": "Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.",
"keywords": [ "keywords": [
"olssonm", "olssonm",
"zxcvbn", "zxcvbn",
@ -10,7 +10,7 @@
"validation", "validation",
"laravel" "laravel"
], ],
"homepage": "https://github.com/olssonm/l5-zxcvbn", "homepage": "https://github.com/olssonm/laravel-zxcvbn",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {
@ -20,13 +20,13 @@
} }
], ],
"require": { "require": {
"php" : ">=7.1.3", "php": "^7.3|^8.0",
"illuminate/support": "^5.8", "illuminate/support": "^7.0|^8.0|^9.0",
"bjeavons/zxcvbn-php": "0.4.0" "bjeavons/zxcvbn-php": "^1.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit" : "~7.0", "phpunit/phpunit": "^8.0|^9.0",
"orchestra/testbench": "^3.8.0" "orchestra/testbench": ">=4.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -51,5 +51,6 @@
] ]
} }
}, },
"minimum-stability": "stable" "minimum-stability": "dev",
"prefer-stable": true
} }

View File

@ -36,7 +36,7 @@ class ZxcvbnServiceProvider extends ServiceProvider
}); });
/** /**
* Extend the Laravel Validator with the "zxcvbn_min" rule * Extend the Laravel Validator with the "zxcvbn_dictionary" rule
*/ */
Validator::extend('zxcvbn_dictionary', function($attribute, $value, $parameters) { Validator::extend('zxcvbn_dictionary', function($attribute, $value, $parameters) {
$email = null; $email = null;
@ -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();
}); });
} }

View File

@ -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];