1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Laravel Password package. |
5
|
|
|
* |
6
|
|
|
* (c) Prosper Otemuyiwa <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Unicodeveloper\DumbPassword; |
13
|
|
|
|
14
|
|
|
use Illuminate\Support\ServiceProvider; |
15
|
|
|
use Illuminate\Support\Facades\Cache; |
16
|
|
|
use Validator; |
17
|
|
|
|
18
|
|
|
class DumbPasswordServiceProvider extends ServiceProvider |
19
|
|
|
{ |
20
|
|
|
/* |
21
|
|
|
* Indicates if loading of the provider is deferred. |
22
|
|
|
* |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
protected $defer = false; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Default error message. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $message = 'This password is just too common. Please try another!'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Publishes all the config file this package needs to function. |
36
|
|
|
*/ |
37
|
|
|
public function boot() |
38
|
|
|
{ |
39
|
|
|
Validator::extend('dumbpwd', function ($attribute, $value, $parameters, $validator) { |
|
|
|
|
40
|
|
|
$path = realpath(__DIR__ . '/../resources/config/passwordlist.txt'); |
41
|
|
|
$cache_key = md5_file($path); |
42
|
|
|
$data = Cache::rememberForever('dumbpwd_list_' . $cache_key, function () use ($path) { |
43
|
|
|
return collect(explode("\n", file_get_contents($path))) |
44
|
|
|
->map(function ($password) { |
45
|
|
|
return strtolower($password); |
46
|
|
|
}); |
47
|
|
|
}); |
48
|
|
|
return !$data->contains(strtolower($value)); |
49
|
|
|
}, $this->message); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Register the application services. |
54
|
|
|
*/ |
55
|
|
|
public function register() |
56
|
|
|
{ |
57
|
|
|
// |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the services provided by the provider. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function provides() |
66
|
|
|
{ |
67
|
|
|
return ['laravel-password']; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.