Skip to content

Commit 7fd84ae

Browse files
[12.x] document the password reset cache driver (#10534)
* document the password reset `cache` driver document laravel/framework#53428 I modeled the wording and organization after the `session.md` docs for hopefully a little consistency. * add note about how we key the entries * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 76b7dfa commit 7fd84ae

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

passwords.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Resetting Passwords
22

33
- [Introduction](#introduction)
4+
- [Configuration](#configuration)
5+
- [Driver Prerequisites](#driver-prerequisites)
46
- [Model Preparation](#model-preparation)
5-
- [Database Preparation](#database-preparation)
67
- [Configuring Trusted Hosts](#configuring-trusted-hosts)
78
- [Routing](#routing)
89
- [Requesting the Password Reset Link](#requesting-the-password-reset-link)
@@ -18,18 +19,54 @@ Most web applications provide a way for users to reset their forgotten passwords
1819
> [!NOTE]
1920
> Want to get started fast? Install a Laravel [application starter kit](/docs/{{version}}/starter-kits) in a fresh Laravel application. Laravel's starter kits will take care of scaffolding your entire authentication system, including resetting forgotten passwords.
2021
22+
<a name="configuration"></a>
23+
### Configuration
24+
25+
Your application's password reset configuration file is stored at `config/auth.php`. Be sure to review the options available to you in this file. By default, Laravel is configured to use the `database` password reset driver.
26+
27+
The password reset `driver` configuration option defines where password reset data will be stored. Laravel includes two drivers:
28+
29+
<div class="content-list" markdown="1">
30+
31+
- `database` - password reset data is stored in a relational database.
32+
- `cache` - password reset data is stored in one of your cache based stores.
33+
34+
</div>
35+
36+
<a name="driver-prerequisites"></a>
37+
### Driver Prerequisites
38+
39+
<a name="database"></a>
40+
#### Database
41+
42+
When using the default `database` driver, a table must be created to store your application's password reset tokens. Typically, this is included in Laravel's default `0001_01_01_000000_create_users_table.php` database migration.
43+
44+
<a name="cache"></a>
45+
#### Cache
46+
47+
There is also a cache driver available for handling password resets, which does not require a dedicated database table. Entries are keyed by the user's email address, so ensure you are not using email addresses as a cache key elsewhere in your application:
48+
49+
```php
50+
'passwords' => [
51+
'users' => [
52+
'driver' => 'cache',
53+
'provider' => 'users',
54+
'store' => 'passwords', // Optional...
55+
'expire' => 60,
56+
'throttle' => 60,
57+
],
58+
],
59+
```
60+
61+
To prevent a call to `artisan cache:clear` from flushing your password reset data, you can optionally specify a separate cache store with the `store` configuration key. The value should correspond to a store configured in your `config/cache.php` configuration value.
62+
2163
<a name="model-preparation"></a>
2264
### Model Preparation
2365

2466
Before using the password reset features of Laravel, your application's `App\Models\User` model must use the `Illuminate\Notifications\Notifiable` trait. Typically, this trait is already included on the default `App\Models\User` model that is created with new Laravel applications.
2567

2668
Next, verify that your `App\Models\User` model implements the `Illuminate\Contracts\Auth\CanResetPassword` contract. The `App\Models\User` model included with the framework already implements this interface, and uses the `Illuminate\Auth\Passwords\CanResetPassword` trait to include the methods needed to implement the interface.
2769

28-
<a name="database-preparation"></a>
29-
### Database Preparation
30-
31-
A table must be created to store your application's password reset tokens. Typically, this is included in Laravel's default `0001_01_01_000000_create_users_table.php` database migration.
32-
3370
<a name="configuring-trusted-hosts"></a>
3471
### Configuring Trusted Hosts
3572

@@ -160,7 +197,7 @@ Before moving on, you may be wondering how Laravel knows how to retrieve the use
160197
<a name="deleting-expired-tokens"></a>
161198
## Deleting Expired Tokens
162199

163-
Password reset tokens that have expired will still be present within your database. However, you may easily delete these records using the `auth:clear-resets` Artisan command:
200+
If you are using the `database` driver, password reset tokens that have expired will still be present within your database. However, you may easily delete these records using the `auth:clear-resets` Artisan command:
164201

165202
```shell
166203
php artisan auth:clear-resets

0 commit comments

Comments
 (0)