Compare commits
13 Commits
f1b74e0f99
...
1ea671c7fe
| Author | SHA1 | Date |
|---|---|---|
|
|
1ea671c7fe | |
|
|
7032f90820 | |
|
|
4fff615d5f | |
|
|
52da9e5fa2 | |
|
|
235147e935 | |
|
|
b494aa89f9 | |
|
|
5128d310eb | |
|
|
7cf2acd39f | |
|
|
8df76e3c62 | |
|
|
2e0534b729 | |
|
|
341a596189 | |
|
|
e643e830f7 | |
|
|
fc3b58165b |
|
|
@ -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,2 +1,3 @@
|
|||
/vendor
|
||||
composer.lock
|
||||
/.phpunit.result.cache
|
||||
|
|
|
|||
|
|
@ -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
|
||||
17
.travis.yml
17
.travis.yml
|
|
@ -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.*
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# 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
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
45
README.md
45
README.md
|
|
@ -1,16 +1,15 @@
|
|||
# Zxcvbn for Laravel 5
|
||||
# Zxcvbn for Laravel
|
||||
|
||||
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||
[![Total downloads][ico-downloads]][link-packagist]
|
||||
[![Software License][ico-license]](LICENSE.md)
|
||||
[![Build Status][ico-travis]][link-travis]
|
||||
[![Scrutinizer Score][ico-scrutinizer]][link-scrutinizer]
|
||||
[](https://github.com/olssonm/ampersand/actions/workflows/test.yml)
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||
|
|
@ -20,14 +19,6 @@ Via Composer
|
|||
$ 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:
|
||||
|
||||
```php
|
||||
|
|
@ -54,17 +45,19 @@ class MyClass extends MyOtherClass
|
|||
$zxcvbn = Zxcvbn::passwordStrength('password');
|
||||
dd($zxcvbn);
|
||||
|
||||
// array:6 [▼
|
||||
// "crack_time" => 5.0E-5
|
||||
// "calc_time" => 0.12961101531982
|
||||
// "password" => "password"
|
||||
// "entropy" => 0.0
|
||||
// "match_sequence" => array:1 []
|
||||
// "score" => 0
|
||||
// array:9 [
|
||||
// "password" => "password"
|
||||
// "guesses" => 3
|
||||
// "guesses_log10" => 0.47712125471966
|
||||
// "sequence" => array:1 []
|
||||
// "crack_times_seconds" => array:4 []
|
||||
// "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.
|
||||
|
|
@ -116,7 +109,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
|
|||
'email' => 'trash@thedumpster.com'
|
||||
];
|
||||
$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());
|
||||
|
|
@ -131,7 +124,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
|
|||
'email' => 'mycomplicatedphrase@thedumpster.com'
|
||||
];
|
||||
$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());
|
||||
|
|
@ -154,7 +147,7 @@ $ phpunit
|
|||
|
||||
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
|
||||
|
||||
|
|
@ -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-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
|
||||
|
||||
[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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "olssonm/l5-zxcvbn",
|
||||
"description": "Implementation of the zxcvbn project by @dropbox for Laravel 5. Uses zxcvbn-php by @bjeavons.",
|
||||
"name": "olssonm/laravel-zxcvbn",
|
||||
"description": "Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.",
|
||||
"keywords": [
|
||||
"olssonm",
|
||||
"zxcvbn",
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
"validation",
|
||||
"laravel"
|
||||
],
|
||||
"homepage": "https://github.com/olssonm/l5-zxcvbn",
|
||||
"homepage": "https://github.com/olssonm/laravel-zxcvbn",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
|
|
@ -20,13 +20,13 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php" : ">=7.1.3",
|
||||
"illuminate/support": "^5.8",
|
||||
"bjeavons/zxcvbn-php": "0.4.0"
|
||||
"php": "^7.3|^8.0",
|
||||
"illuminate/support": "^7.0|^8.0|^9.0",
|
||||
"bjeavons/zxcvbn-php": "^1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit" : "~7.0",
|
||||
"orchestra/testbench": "^3.8.0"
|
||||
"phpunit/phpunit": "^8.0|^9.0",
|
||||
"orchestra/testbench": ">=4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
@ -51,5 +51,6 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable"
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
$email = null;
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ class ZxcvbnServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind('zxcvbn', function($app) {
|
||||
$this->app->bind('zxcvbn', function() {
|
||||
return new ZxcvbnPhp();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,15 +38,17 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
|
|||
*/
|
||||
public function test_zxcvbn_basics()
|
||||
{
|
||||
$zxcvbn = Zxcvbn::passwordStrength('password');
|
||||
|
||||
$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 +59,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 +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'));
|
||||
}
|
||||
|
||||
/** @note validation helper */
|
||||
private function validate_without_message_min($password, $min)
|
||||
{
|
||||
$data = ['password' => $password];
|
||||
|
|
@ -116,6 +119,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 +133,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 +144,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];
|
||||
|
|
|
|||
Loading…
Reference in New Issue