@@ -17,28 +17,36 @@ This package can be used to enhance the user security of Laravel projects.
1717
1818## Installation
1919
20- [ PHP] ( https://php.net ) 5.5+ or [ HHVM] ( http://hhvm.com ) 3.3+, and [ Composer] ( https://getcomposer.org ) are required.
20+ Requirements:
21+ - [ PHP] ( https://php.net ) 5.5+
22+ - [ Composer] ( https://getcomposer.org )
2123
22- To get the latest version of Laravel Security, simply add the following line to the require block of your ` composer.json ` file.
24+ To get the latest version of Laravel Security, simply run:
2325
2426```
2527composer require sicaboy/laravel-security
28+ ```
29+
30+ Then do vendor publish:
2631
32+ ```
2733php artisan vendor:publish --provider="Sicaboy\LaravelSecurity\LaravelSecurityServiceProvider"
2834```
2935
30- - If you're on Laravel 5.5 or above, that's all you need to do! Check out the usage examples below.
3136- 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:
3237
3338``` php
34- Siaboy\LaravelSecurity\LaravelSecurityServiceProvider::class
39+ Siaboy\LaravelSecurity\LaravelSecurityServiceProvider::class,
40+ Siaboy\LaravelSecurity\Providers\EventSecurityServiceProvider::class,
3541```
3642
43+ # Validators
44+
3745## Available Rules
3846
39- - [ NotCommonPassword] ( src/Rules/NotCommonPassword.php )
47+ - [ NotCommonPassword] ( src/Rules/NotCommonPassword.php ) - Avoid user to use a common used password
4048
41- - [ NotAUsedPassword] ( src/Rules/NotAUsedPassword.php )
49+ - [ NotAUsedPassword] ( src/Rules/NotAUsedPassword.php ) - Avoid user to use a password which has been used before
4250
4351
4452## Usage
@@ -61,17 +69,29 @@ public function rules()
6169 //...
6270 new \Sicaboy\LaravelSecurity\Rules\NotCommonPassword(),
6371 new \Sicaboy\LaravelSecurity\Rules\NotAUsedPassword(),
64- // or only check used password for a specific user:
72+ // or only check used password for a specific user (e.g. on user password change) :
6573 // new \Sicaboy\LaravelSecurity\Rules\NotAUsedPassword($userId),
66- // Also you need to call handler function mentioned in the next section
74+ // Also you need to call event, examples in the next section
6775 ],
6876 ];
6977}
7078```
7179
72- ## Additional method you need to call when you use NotAUsedPassword
80+ ## Event you need to call
81+
82+ There are events you should add to coresponding methods.
83+
84+ - If you use ` NotAUsedPassword ` validator, you need to call the following events:
85+
86+ ``` php
87+ // Call on user regration
88+ event(new \Sicaboy\LaravelSecurity\Events\UserRegistered($user, $newPlainPassword));
89+
90+ // Call on user password change
91+ event(new \Sicaboy\LaravelSecurity\Events\UserPasswordChanged($user, $newPlainPassword));
92+ ```
7393
74- You need to call ` NotAUsedPasswordHandler::lodgePassword ` when the user is created and changes the password. If you use ` NotAUsedPassword ` validator.
94+ Example:
7595
7696``` php
7797 protected function create(array $data)
@@ -81,8 +101,8 @@ You need to call `NotAUsedPasswordHandler::lodgePassword` when the user is creat
81101 'email' => $data['email'],
82102 'password' => Hash::make($data['password']),
83103 ]);
84-
85- \Sicaboy\LaravelSecurity\Handlers\NotAUsedPasswordHandler::lodgePassword ($user->id , $data['password']);
104+
105+ event(new \Sicaboy\LaravelSecurity\Events\UserRegistered ($user, $data['password']) );
86106
87107 return $user;
88108 }
0 commit comments