Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii 2.0 authentication in UserIdentity without database

Tags:

yii2

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 ?

like image 662
user7282 Avatar asked Nov 03 '14 10:11

user7282


People also ask

How does Yii authentication work?

It usually uses an identifier (e.g. a username or an email address) and a secret token (e.g. a password or an access token) to judge if the user is the one whom he claims as. Authentication is the basis of the login feature. Yii provides an authentication framework which wires up various components to support login.

Is Yii Framework open source?

Like Symphony and Laravel, Yii2 is an open-source framework for both back-end and front-end programming. A lot of explanatory documentation helps to sort out many issues and the framework is also supported by a community of significant size. Yii also supports Object-Relational Mapping.

Why Yii is the best framework?

Excellent Security. The security feature is one of the top reasons to choose Yii over other frameworks. This fast, robust framework helps you build a more secure web app and prevents your application from cyberattacks.

What is isGuest in Yii2?

You may use $isGuest to determine whether the current user is a guest or not. If the user is a guest, the $identity property would return null . Otherwise, it would be an instance of yii\web\IdentityInterface.


1 Answers

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.

like image 127
tripskeet Avatar answered Sep 28 '22 01:09

tripskeet