You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on the scope of your application, there may be times when you'll decide that it is absolutely necessary to force user(s) to reset their password. This practice is common when you find out that users of your application do not use strong passwords OR there is a reasonable suspicion that their passwords have been compromised. This guide provides you with ways to achieve this.
-[Check if a User Requires Password Reset](#check-if-a-user-requires-password-reset)
8
+
-[Force Password Reset On a User](#force-password-reset-on-a-user)
9
+
-[Removing Password Reset Flag On a User](#removing-password-reset-flag-on-a-user)
10
+
-[Force Password Reset On Multiple Users](#force-password-reset-on-multiple-users)
11
+
-[Force Password Reset On All Users](#force-password-reset-on-all-users)
12
+
13
+
## Available Methods
14
+
15
+
Shield provides a way to enforce password resets throughout your application. The `Resettable` trait on the `User` entity and the `UserIdentityModel` provides the following methods to do so.
16
+
17
+
### Check if a User Requires Password Reset
18
+
19
+
When you need to check if a user requires password reset, you can do so using the `requiresPasswordReset()` method on the `User` entity. Returns boolean `true`/`false`.
20
+
21
+
```php
22
+
if ($user->requiresPasswordReset()) {
23
+
//...
24
+
}
25
+
```
26
+
27
+
### Force Password Reset On a User
28
+
29
+
To force password reset on a user, you can do so using the `forcePasswordReset()` method on the `User` entity.
30
+
31
+
```php
32
+
$user->forcePasswordReset();
33
+
```
34
+
35
+
### Remove Force Password Reset Flag On a User
36
+
37
+
Undoing or removing the force password reset flag on a user can be done using the `undoForcePasswordReset()` method on the `User` entity.
38
+
39
+
```php
40
+
$user->undoForcePasswordReset();
41
+
```
42
+
43
+
### Force Password Reset On Multiple Users
44
+
45
+
If you see the need to force password reset for more than one user, the `forceMultiplePasswordReset()` method of the `UserIdentityModel` allows you to do this easily. It accepts an `Array` of user IDs.
If you suspect a security breach or compromise in the passwords of your users, you can easily force password reset on all the users of your application using the `forceGlobalPasswordReset()` method of the `UserIdentityModel`.
These instructions assume that you have already [installed the CodeIgniter 4 app starter](https://codeigniter.com/user_guide/installation/installing_composer.html) as the basis for your new project, set up your **.env** file, and created a database that you can access via the Spark CLI script.
@@ -206,6 +208,7 @@ chained | The filter will check both authenticators in sequence to see if the us
206
208
auth-rates | Provides a good basis for rate limiting of auth-related routes.
207
209
group | Checks if the user is in one of the groups passed in.
208
210
permission | Checks if the user has the passed permissions.
211
+
force-reset | Checks if the user requires a password reset.
209
212
210
213
These can be used in any of the [normal filter config settings](https://codeigniter.com/user_guide/incoming/filters.html#globals), or [within the routes file](https://codeigniter.com/user_guide/incoming/routing.html#applying-filters).
211
214
@@ -241,6 +244,21 @@ public $filters = [
241
244
];
242
245
```
243
246
247
+
### Forcing Password Reset
248
+
249
+
If your application requires a force password reset functionality, ensure that you exclude the auth pages and the actual password reset page from the `before` global. This will ensure that your users do not run into a *too many redirects* error. See:
In the example above, it is assumed that the page you have created for users to change their password after successful login is **change-password**.
261
+
244
262
> **Note** If you have grouped or changed the default format of the routes, ensure that your code matches the new format(s) in the **app/Config/Filter.php** file.
245
263
246
264
For example, if you configured your routes like so:
@@ -260,4 +278,4 @@ public $globals = [
260
278
]
261
279
]
262
280
```
263
-
The same should apply for the Rate Limiting.
281
+
The same should apply for the Rate Limiting and Forcing Password Reset.
0 commit comments