This tutorial explains how to make login functionality with users coming from database. Login functionality is one of the most important parts of every application.
Here you will learn how to handle autologin using cookies, how to handle authKey column, and how to properly implement UserIdentity interface.
More details you can find on: http://code-epicenter.com/how-to-login-user-from-a-database-in-yii-framework-2/
source