Yii2: Why is the auth key in class User?

后端 未结 2 1113
清歌不尽
清歌不尽 2020-12-29 02:54

As the title clarifies why is the auth key introduced in Yii2? What\'re it\'s main usages and how it is useful in authentication?

2条回答
  •  死守一世寂寞
    2020-12-29 03:30

    As explained previously, you only need to implement getAuthKey() and validateAuthKey() if your application uses cookie-based login feature. In this case, you may use the following code to generate an auth key for each user and store it in the user table:

    More details can be found in official documentation: https://www.yiiframework.com/doc/guide/2.0/en/security-authentication

提交回复
热议问题