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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.