|
25 | 25 | - [Adding Custom User Providers](#adding-custom-user-providers)
|
26 | 26 | - [The User Provider Contract](#the-user-provider-contract)
|
27 | 27 | - [The Authenticatable Contract](#the-authenticatable-contract)
|
| 28 | +- [Automatic Password Rehashing](#automatic-password-rehashing) |
28 | 29 | - [Social Authentication](/docs/{{version}}/socialite)
|
29 | 30 | - [Events](#events)
|
30 | 31 |
|
@@ -52,7 +53,9 @@ Want to get started fast? Install a [Laravel application starter kit](/docs/{{ve
|
52 | 53 | <a name="introduction-database-considerations"></a>
|
53 | 54 | ### Database Considerations
|
54 | 55 |
|
55 |
| -By default, Laravel includes an `App\Models\User` [Eloquent model](/docs/{{version}}/eloquent) in your `app/Models` directory. This model may be used with the default Eloquent authentication driver. If your application is not using Eloquent, you may use the `database` authentication provider which uses the Laravel query builder. |
| 56 | +By default, Laravel includes an `App\Models\User` [Eloquent model](/docs/{{version}}/eloquent) in your `app/Models` directory. This model may be used with the default Eloquent authentication driver. |
| 57 | + |
| 58 | +If your application is not using Eloquent, you may use the `database` authentication provider which uses the Laravel query builder. If your application is using MongoDB, check out MongoDB's official [Laravel user authentication documentation](https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/user-authentication/) . |
56 | 59 |
|
57 | 60 | When building the database schema for the `App\Models\User` model, make sure the password column is at least 60 characters in length. Of course, the `users` table migration that is included in new Laravel applications already creates a column that exceeds this length.
|
58 | 61 |
|
@@ -181,7 +184,7 @@ To determine if the user making the incoming HTTP request is authenticated, you
|
181 | 184 | <a name="protecting-routes"></a>
|
182 | 185 | ### Protecting Routes
|
183 | 186 |
|
184 |
| -[Route middleware](/docs/{{version}}/middleware) can be used to only allow authenticated users to access a given route. Laravel ships with an `auth` middleware, which is a [middleware alias](/docs/{{version}}/middleware#middleware-alias) for the `Illuminate\Auth\Middleware\Authenticate` class. Since this middleware is already aliased internally by Laravel, all you need to do is attach the middleware to a route definition: |
| 187 | +[Route middleware](/docs/{{version}}/middleware) can be used to only allow authenticated users to access a given route. Laravel ships with an `auth` middleware, which is a [middleware alias](/docs/{{version}}/middleware#middleware-aliases) for the `Illuminate\Auth\Middleware\Authenticate` class. Since this middleware is already aliased internally by Laravel, all you need to do is attach the middleware to a route definition: |
185 | 188 |
|
186 | 189 | Route::get('/flights', function () {
|
187 | 190 | // Only authenticated users may access this route...
|
@@ -279,8 +282,8 @@ For complex query conditions, you may provide a closure in your array of credent
|
279 | 282 | use Illuminate\Database\Eloquent\Builder;
|
280 | 283 |
|
281 | 284 | if (Auth::attempt([
|
282 |
| - 'email' => $email, |
283 |
| - 'password' => $password, |
| 285 | + 'email' => $email, |
| 286 | + 'password' => $password, |
284 | 287 | fn (Builder $query) => $query->has('activeSubscription'),
|
285 | 288 | ])) {
|
286 | 289 | // Authentication was successful...
|
@@ -359,9 +362,9 @@ To authenticate a user using their database record's primary key, you may use th
|
359 | 362 |
|
360 | 363 | Auth::loginUsingId(1);
|
361 | 364 |
|
362 |
| -You may pass a boolean value as the second argument to the `loginUsingId` method. This value indicates if "remember me" functionality is desired for the authenticated session. Remember, this means that the session will be authenticated indefinitely or until the user manually logs out of the application: |
| 365 | +You may pass a boolean value to the `remember` argument of the `loginUsingId` method. This value indicates if "remember me" functionality is desired for the authenticated session. Remember, this means that the session will be authenticated indefinitely or until the user manually logs out of the application: |
363 | 366 |
|
364 |
| - Auth::loginUsingId(1, $remember = true); |
| 367 | + Auth::loginUsingId(1, remember: true); |
365 | 368 |
|
366 | 369 | <a name="authenticate-a-user-once"></a>
|
367 | 370 | #### Authenticate a User Once
|
@@ -457,7 +460,7 @@ In addition to calling the `logout` method, it is recommended that you invalidat
|
457 | 460 |
|
458 | 461 | Laravel also provides a mechanism for invalidating and "logging out" a user's sessions that are active on other devices without invalidating the session on their current device. This feature is typically utilized when a user is changing or updating their password and you would like to invalidate sessions on other devices while keeping the current device authenticated.
|
459 | 462 |
|
460 |
| -Before getting started, you should make sure that the `Illuminate\Session\Middleware\AuthenticateSession` middleware is included on the routes that should receive session authentication. Typically, you should place this middleware on a route group definition so that it can be applied to the majority of your application's routes. By default, the `AuthenticateSession` middleware may be attached to a route using the `auth.session` [middleware alias](/docs/{{version}}/middleware#middleware-alias): |
| 463 | +Before getting started, you should make sure that the `Illuminate\Session\Middleware\AuthenticateSession` middleware is included on the routes that should receive session authentication. Typically, you should place this middleware on a route group definition so that it can be applied to the majority of your application's routes. By default, the `AuthenticateSession` middleware may be attached to a route using the `auth.session` [middleware alias](/docs/{{version}}/middleware#middleware-aliases): |
461 | 464 |
|
462 | 465 | Route::middleware(['auth', 'auth.session'])->group(function () {
|
463 | 466 | Route::get('/', function () {
|
@@ -716,22 +719,45 @@ This interface is simple. The `getAuthIdentifierName` method should return the n
|
716 | 719 |
|
717 | 720 | This interface allows the authentication system to work with any "user" class, regardless of what ORM or storage abstraction layer you are using. By default, Laravel includes an `App\Models\User` class in the `app/Models` directory which implements this interface.
|
718 | 721 |
|
| 722 | +<a name="automatic-password-rehashing"></a> |
| 723 | +## Automatic Password Rehashing |
| 724 | + |
| 725 | +Laravel's default password hashing algorithm is bcrypt. The "work factor" for bcrypt hashes can be adjusted via your application's `config/hashing.php` configuration file or the `BCRYPT_ROUNDS` environment variable. |
| 726 | + |
| 727 | +Typically, the bcrypt work factor should be increased over time as CPU / GPU processing power increases. If you increase the bcrypt work factor for your application, Laravel will gracefully and automatically rehash user passwords as users authenticate with your application via Laravel's starter kits or when you [manually authenticate users](#authenticating-users) via the `attempt` method. |
| 728 | + |
| 729 | +Typically, automatic password rehashing should not disrupt your application; however, you may disable this behavior by publishing the `hashing` configuration file: |
| 730 | + |
| 731 | +```shell |
| 732 | +php artisan config:publish hashing |
| 733 | +``` |
| 734 | + |
| 735 | +Once the configuration file has been published, you may set the `rehash_on_login` configuration value to `false`: |
| 736 | + |
| 737 | +```php |
| 738 | +'rehash_on_login' => false, |
| 739 | +``` |
| 740 | + |
719 | 741 | <a name="events"></a>
|
720 | 742 | ## Events
|
721 | 743 |
|
722 | 744 | Laravel dispatches a variety of [events](/docs/{{version}}/events) during the authentication process. You may [define listeners](/docs/{{version}}/events) for any of the following events:
|
723 | 745 |
|
724 |
| -Event Name | |
725 |
| -------------- | |
726 |
| -`Illuminate\Auth\Events\Registered` | |
727 |
| -`Illuminate\Auth\Events\Attempting` | |
728 |
| -`Illuminate\Auth\Events\Authenticated` | |
729 |
| -`Illuminate\Auth\Events\Login` | |
730 |
| -`Illuminate\Auth\Events\Failed` | |
731 |
| -`Illuminate\Auth\Events\Validated` | |
732 |
| -`Illuminate\Auth\Events\Verified` | |
733 |
| -`Illuminate\Auth\Events\Logout` | |
734 |
| -`Illuminate\Auth\Events\CurrentDeviceLogout` | |
735 |
| -`Illuminate\Auth\Events\OtherDeviceLogout` | |
736 |
| -`Illuminate\Auth\Events\Lockout` | |
737 |
| -`Illuminate\Auth\Events\PasswordReset` | |
| 746 | +<div class="overflow-auto"> |
| 747 | + |
| 748 | +| Event Name | |
| 749 | +| --- | |
| 750 | +| `Illuminate\Auth\Events\Registered` | |
| 751 | +| `Illuminate\Auth\Events\Attempting` | |
| 752 | +| `Illuminate\Auth\Events\Authenticated` | |
| 753 | +| `Illuminate\Auth\Events\Login` | |
| 754 | +| `Illuminate\Auth\Events\Failed` | |
| 755 | +| `Illuminate\Auth\Events\Validated` | |
| 756 | +| `Illuminate\Auth\Events\Verified` | |
| 757 | +| `Illuminate\Auth\Events\Logout` | |
| 758 | +| `Illuminate\Auth\Events\CurrentDeviceLogout` | |
| 759 | +| `Illuminate\Auth\Events\OtherDeviceLogout` | |
| 760 | +| `Illuminate\Auth\Events\Lockout` | |
| 761 | +| `Illuminate\Auth\Events\PasswordReset` | |
| 762 | + |
| 763 | +</div> |
0 commit comments