Compare commits

..

No commits in common. "1ea671c7fea1a1fbfb10e03b7e1d971d3c856143" and "f1b74e0f99cb1c7ac9e9df661200debd3aa8a2e4" have entirely different histories.

9 changed files with 80 additions and 91 deletions

View File

@ -1,45 +0,0 @@
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,3 +1,2 @@
/vendor
composer.lock
/.phpunit.result.cache

18
.scrutinizer.yml Normal file
View File

@ -0,0 +1,18 @@
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 Normal file
View File

@ -0,0 +1,17 @@
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)
Copyright (c) 2020 Marcus Olsson <contact@marcusolsson.me>
Copyright (c) 2018 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

View File

@ -1,15 +1,16 @@
# Zxcvbn for Laravel
# Zxcvbn for Laravel 5
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total downloads][ico-downloads]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![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)
[![Build Status][ico-travis]][link-travis]
[![Scrutinizer Score][ico-scrutinizer]][link-scrutinizer]
![zxcvbn](https://user-images.githubusercontent.com/907114/41193108-747d9b50-6c08-11e8-8f9c-57874f52fa9b.png)
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.
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) and [@mkopinsky](https://github.com/mkopinsky), 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), which in turn is inspired by [zxcvbn](https://github.com/dropbox/zxcvbn) by [@dropbox](https://github.com/dropbox).
## Install
@ -19,6 +20,14 @@ 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
@ -45,19 +54,17 @@ class MyClass extends MyOtherClass
$zxcvbn = Zxcvbn::passwordStrength('password');
dd($zxcvbn);
// 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
// array:6 [▼
// "crack_time" => 5.0E-5
// "calc_time" => 0.12961101531982
// "password" => "password"
// "entropy" => 0.0
// "match_sequence" => array:1 []
// "score" => 0
// ]
}
}
?>
```
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.
@ -109,7 +116,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
'email' => 'trash@thedumpster.com'
];
$validator = Validator::make($password, [
'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $data['username'], $data['email'])
'password' => 'zxcvbn_dictionary:' . $data['username'] . ',' . $data['email'] . '|required',
]);
dd($validator->passes());
@ -124,7 +131,7 @@ This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the
'email' => 'mycomplicatedphrase@thedumpster.com'
];
$validator = Validator::make($password, [
'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $data['username'], $data['email'])
'password' => 'zxcvbn_dictionary:' . $data['username'] . ',' . $data['email'] . '|required',
]);
dd($validator->passes());
@ -147,7 +154,7 @@ $ phpunit
The MIT License (MIT). Please see the [License File](LICENSE.md) for more information.
© 2020 [Marcus Olsson](https://marcusolsson.me).
© 2018 [Marcus Olsson](https://marcusolsson.me).
[ico-version]: https://img.shields.io/packagist/v/olssonm/l5-zxcvbn.svg?style=flat-square
@ -155,12 +162,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/laravel-zxcvbn/master.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/olssonm/l5-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/laravel-zxcvbn
[link-travis]: https://travis-ci.org/olssonm/l5-zxcvbn
[link-scrutinizer]: https://scrutinizer-ci.com/g/olssonm/l5-zxcvbn

View File

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

View File

@ -36,7 +36,7 @@ class ZxcvbnServiceProvider extends ServiceProvider
});
/**
* Extend the Laravel Validator with the "zxcvbn_dictionary" rule
* Extend the Laravel Validator with the "zxcvbn_min" 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['sequence'][0])) {
$dictionary = $zxcvbn['sequence'][0];
if (isset($zxcvbn['match_sequence'][0])) {
$dictionary = $zxcvbn['match_sequence'][0];
if (isset($dictionary->dictionaryName)) {
return false;
}
@ -74,7 +74,7 @@ class ZxcvbnServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind('zxcvbn', function() {
$this->app->bind('zxcvbn', function($app) {
return new ZxcvbnPhp();
});
}

View File

@ -38,17 +38,15 @@ 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('sequence', $testVar1);
$this->assertArrayHasKey('crack_times_seconds', $testVar1);
$this->assertArrayHasKey('crack_times_display', $testVar1);
$this->assertArrayHasKey('match_sequence', $testVar1);
$this->assertArrayHasKey('entropy', $testVar1);
$this->assertArrayHasKey('password', $testVar1);
$this->assertArrayHasKey('calc_time', $testVar1);
$this->assertArrayHasKey('guesses', $testVar1);
$this->assertArrayHasKey('crack_time', $testVar1);
// Check score-value
$this->assertEquals(0, $testVar1['score']);
@ -59,7 +57,7 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
$testVar4 = Zxcvbn::passwordStrength('7E6k9axB*gwGHa&aZTohmD9Wr&NVs[b4'); //<-- 32
// Check score-value
$this->assertEquals(2, $testVar2['score']);
$this->assertEquals(1, $testVar2['score']);
$this->assertEquals(4, $testVar3['score']);
$this->assertEquals(4, $testVar4['score']);
}
@ -108,7 +106,6 @@ 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];
@ -119,7 +116,6 @@ class ZxcvbnTest extends \Orchestra\Testbench\TestCase {
return $validator->passes();
}
/** @note validation helper */
private function validate_with_message_min($password, $min, $message)
{
$data = ['password' => $password];
@ -133,7 +129,6 @@ 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];
@ -144,7 +139,6 @@ 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];