Authentication

Most web applications provide a way for users to log in or reset their forgotten passwords. In Yii2, we don't have this opportunity by default. For a basic application template, Yii provides only two test users by default, which are statically described in the User model. So, we have to implement special code to be able to enable user login from the database.

Getting ready

  1. Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
  2. In the component section of your config, add:
    'user' => [
        'identityClass' => 'app\models\User',
        'enableAutoLogin' => true,
    ],
  3. Create a User table. Create a migration by entering the following command: ...

Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.