user7282
user7282

Reputation: 5196

Yii 2.0 authentication in UserIdentity without database

Any idea about authentication without using database?. I have gone through the basic template. In that app/models/User.php ,they have provided validations based on

 private static $users = [
        '100' => [
            'id' => '100',
            'username' => 'admin',
            'password' => 'admin',
            'authKey' => 'test100key',
            'accessToken' => '100-token',
        ],
        '101' => [
            'id' => '101',
            'username' => 'demo',
            'password' => 'demo',
            'authKey' => 'test101key',
            'accessToken' => '101-token',
        ],
    ];

But I want the login validation based on a different condition , for example if a variable satisfies some conditions , the he should be logged on. Or any idea on whether I can set Identity Manually?

I referred to http://www.yiiframework.com/doc-2.0/yii-web-identityinterface.html , it also mentions about only using database. Is it necessary to set 'authKey' and 'accessToken' ?

Or anyone can explain the flow of authentication in Yii 2.0 , which values to be set , in which order ?

Upvotes: 7

Views: 2603

Answers (1)

tripskeet
tripskeet

Reputation: 186

You can roll your own IdentityInterface and have user implement there. But altering your loginForm.php file at the getUser() and validatePassword() methods might work better.

Upvotes: 1

Related Questions