diff --git a/.travis.yml b/.travis.yml
index af76124..ad6b5f6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,8 @@
language: php
php:
- - 5.5
- - 5.6
- 7.0
- - hhvm
+ - 8.0
# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
@@ -17,7 +15,7 @@ cache:
matrix:
include:
- - php: 5.5
+ - php: 7.0
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
before_script:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5b4804..53acea4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,19 +4,18 @@ All Notable changes to `laravel-password` will be documented in this file.
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
-## NEXT - YYYY-MM-DD
+## 2020-12-30
-### Added
-- Nothing
+- Make passwords case insensitive.
+- Support PHP 8
-### Deprecated
-- Nothing
+## 2017-04-26
-### Fixed
-- Nothing
+- Removed the flip method
+- Now uses the collection `contains` method directly.
+- Caching Support
-### Removed
-- Nothing
-### Security
-- Nothing
+## 2017-04-27
+
+- Switch back to a non-defered service provider
diff --git a/README.md b/README.md
index 64f151c..86b7552 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
[](https://scrutinizer-ci.com/g/unicodeveloper/laravel-password)
[](https://packagist.org/packages/unicodeveloper/laravel-password)
-> #### Guard your users from security problems such as being hacked that start by having dumb passwords
+> #### Guard your users from security problems by preventing them from having dumb passwords
### Introduction
@@ -28,10 +28,12 @@ To get the latest version of Laravel Password, simply add the following line to
You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.
-Once Laravel Password is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.
-
-* `Unicodeveloper\DumbPassword\DumbPasswordServiceProvider::class`
+- If you're on Laravel 5.5 or above, that's all you need to do! Check out the usage examples below.
+- If you're on Laravel < 5.5, you'll need to register the service provider. Open up `config/app.php` and add the following to the `providers` array:
+```php
+Unicodeveloper\DumbPassword\DumbPasswordServiceProvider::class
+```
## Usage
@@ -56,8 +58,6 @@ protected function validator(array $data)
Error shows on the page like so:
-
-
By default, the error message returned is `This password is just too common. Please try another!`.
@@ -68,9 +68,11 @@ You can customize the error message by opening `resources/lang/en/validation.php
'dumbpwd' => 'You are using a dumb password abeg',
```
+
+
## Change log
-Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
+Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
diff --git a/composer.json b/composer.json
index 7d53dc5..971ce2a 100644
--- a/composer.json
+++ b/composer.json
@@ -19,10 +19,10 @@
}
],
"require": {
- "php" : "~5.6|~7.0"
+ "php" : "~7.0 || ~8.0"
},
"require-dev": {
- "phpunit/phpunit" : "~4.0||~5.0",
+ "phpunit/phpunit" : "~8.0 || ~9.0",
"scrutinizer/ocular": "~1.1",
"squizlabs/php_codesniffer": "~2.3"
},
@@ -33,7 +33,7 @@
},
"autoload-dev": {
"psr-4": {
- "Unicodeveloper\\DumbPassword\\Test": "tests"
+ "Unicodeveloper\\DumbPassword\\Test\\": "tests"
}
},
"scripts": {
@@ -42,6 +42,11 @@
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
+ },
+ "laravel": {
+ "providers": [
+ "Unicodeveloper\\DumbPassword\\DumbPasswordServiceProvider"
+ ]
}
}
}
diff --git a/src/DumbPasswordServiceProvider.php b/src/DumbPasswordServiceProvider.php
index 7d8a4ee..719e926 100644
--- a/src/DumbPasswordServiceProvider.php
+++ b/src/DumbPasswordServiceProvider.php
@@ -12,11 +12,11 @@
namespace Unicodeveloper\DumbPassword;
use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Cache;
use Validator;
class DumbPasswordServiceProvider extends ServiceProvider
{
-
/*
* Indicates if loading of the provider is deferred.
*
@@ -25,31 +25,43 @@ class DumbPasswordServiceProvider extends ServiceProvider
protected $defer = false;
/**
- * Publishes all the config file this package needs to function
- */
+ * Default error message.
+ *
+ * @var string
+ */
+ protected $message = 'This password is just too common. Please try another!';
+
+ /**
+ * Publishes all the config file this package needs to function.
+ */
public function boot()
{
- $path = realpath(__DIR__.'/../resources/config/passwordlist.txt');
- $dumbPasswords = collect(explode("\n", file_get_contents($path)));
- $data = $dumbPasswords->flip();
-
- Validator::extend('dumbpwd', function($attribute, $value, $parameters, $validator) use ($data) {
- return !$data->has($value);
- }, 'This password is just too common. Please try another!');
+ Validator::extend('dumbpwd', function ($attribute, $value, $parameters, $validator) {
+ $path = realpath(__DIR__ . '/../resources/config/passwordlist.txt');
+ $cache_key = md5_file($path);
+ $data = Cache::rememberForever('dumbpwd_list_' . $cache_key, function () use ($path) {
+ return collect(explode("\n", file_get_contents($path)))
+ ->map(function ($password) {
+ return strtolower($password);
+ });
+ });
+ return !$data->contains(strtolower($value));
+ }, $this->message);
}
/**
- * Register the application services.
- */
+ * Register the application services.
+ */
public function register()
{
-
+ //
}
/**
- * Get the services provided by the provider
- * @return array
- */
+ * Get the services provided by the provider.
+ *
+ * @return array
+ */
public function provides()
{
return ['laravel-password'];
diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php
index a3b4876..974c886 100644
--- a/tests/ExampleTest.php
+++ b/tests/ExampleTest.php
@@ -1,8 +1,9 @@