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 ?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With