|
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 Validator; |
|
16
|
|
|
|
|
17
|
|
|
class DumbPasswordServiceProvider extends ServiceProvider |
|
18
|
|
|
{ |
|
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
|
|
|
$path = realpath(__DIR__.'/../resources/config/passwordlist.txt'); |
|
40
|
|
|
$data = $this->generateDictionary($path); |
|
41
|
|
|
|
|
42
|
|
|
Validator::extend('dumbpwd', function($attribute, $value, $parameters, $validator) use ($data) { |
|
|
|
|
|
|
43
|
|
|
return !array_key_exists($value, $data); |
|
44
|
|
|
}, $this->message); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register the application services. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function register() |
|
51
|
|
|
{ |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the services provided by the provider |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
public function provides() |
|
60
|
|
|
{ |
|
61
|
|
|
return ['laravel-password']; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Generates a dictionary from the file referenced by the path specified |
|
66
|
|
|
* |
|
67
|
|
|
* @param $path |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
private function generateDictionary($path) |
|
72
|
|
|
{ |
|
73
|
|
|
$dictionary = []; |
|
74
|
|
|
|
|
75
|
|
|
$handle = fopen($path, "r"); |
|
76
|
|
|
if ($handle) { |
|
77
|
|
|
while (($line = fgets($handle)) !== false) { |
|
78
|
|
|
$dictionary[trim($line)] = true; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
fclose($handle); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $dictionary; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.