Skip to content

Commit 03351e0

Browse files
committed
applied code review suggestions on docs
1 parent 482c715 commit 03351e0

3 files changed

Lines changed: 68 additions & 64 deletions

File tree

docs/forcing_password_reset.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Forcing Password Reset
2+
3+
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.
4+
5+
- [Forcing Password Reset](#forcing-password-reset)
6+
- [Available Methods](#available-methods)
7+
- [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. Returns boolean `true`/`false`.
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. Returns boolean `true`/`false`.
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.
46+
47+
```php
48+
use CodeIgniter\Shield\Models\UserIdentityModel;
49+
...
50+
...
51+
...
52+
$identities = new UserIdentityModel();
53+
$identities->forceMultiplePasswordReset([1,2,3,4]);
54+
```
55+
56+
### Force Password Reset On All Users
57+
58+
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`.
59+
60+
```php
61+
use CodeIgniter\Shield\Models\UserIdentityModel;
62+
...
63+
...
64+
...
65+
$identities = new UserIdentityModel();
66+
$identities->forceGlobalPasswordReset();
67+
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [Authentication](authentication.md)
77
* [Authorization](authorization.md)
88
* [Auth Actions](auth_actions.md)
9+
* [Forcing Password Reset](forcing_password_reset.md)
910
* [Events](events.md)
1011
* [Testing](testing.md)
1112
* [Customization](customization.md)

docs/quickstart.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ Learning any new authentication system can be difficult, especially as they get
3030
- [Creating Users](#creating-users)
3131
- [Deleting Users](#deleting-users)
3232
- [Editing a User](#editing-a-user)
33-
- [Forcing Password Reset](#forcing-password-reset)
34-
- [requiresPasswordReset()](#requirespasswordreset)
35-
- [forcePaswordReset()](#forcepasswordreset)
36-
- [undoForcePasswordReset()](#undoforcepasswordreset)
37-
- [forceMultiplePasswordReset()](#forcemultiplepasswordreset)
38-
- [forceGlobalPasswordReset()](#forceglobalpasswordreset)
3933

4034
## Authentication Flow
4135

@@ -318,61 +312,3 @@ $user->fill([
318312
]);
319313
$users->save($user);
320314
```
321-
322-
## Forcing Password Reset
323-
324-
Shield provides a way to enforce password resets throughout your application. The `Resettable` trait on the `User` entity provides the following utility methods to do so.
325-
326-
#### requiresPasswordReset()
327-
328-
Allows you to check if a user requires password reset. Returns boolean `true`/`false`.
329-
330-
```php
331-
if ($user->requiresPasswordReset()) {
332-
//...
333-
}
334-
```
335-
336-
#### forcePasswordReset()
337-
338-
Allows you to force password reset on a user. Returns boolean `true`/`false`.
339-
340-
```php
341-
$user->forcePasswordReset();
342-
```
343-
344-
#### undoForcePasswordReset()
345-
346-
Allows you to undo or remove the force password reset flag on a user. Returns boolean `true`/`false`.
347-
348-
```php
349-
$user->undoForcePasswordReset();
350-
```
351-
352-
There are times when you might want to force password reset on multiple users or for all users in your application, maybe due to security breach. The `UserIdentityModel` provides methods to do this easily.
353-
354-
#### forceMultiplePasswordReset()
355-
356-
This allows you to force password reset for multiple users. Accepts an array of user IDs.
357-
358-
```php
359-
use CodeIgniter\Shield\Models\UserIdentityModel;
360-
...
361-
...
362-
...
363-
$identities = new UserIdentityModel();
364-
$identities->forceMultiplePasswordReset([1,2,3,4]);
365-
```
366-
367-
#### forceGlobalPasswordReset()
368-
369-
This allows you to force password reset all the users in your application.
370-
371-
```php
372-
use CodeIgniter\Shield\Models\UserIdentityModel;
373-
...
374-
...
375-
...
376-
$identities = new UserIdentityModel();
377-
$identities->forceGlobalPasswordReset();
378-
```

0 commit comments

Comments
 (0)