W
W
WingRS2017-04-24 20:57:52
Yii
WingRS, 2017-04-24 20:57:52

How to create a custom user in yii2?

Yii2 has its own user, I am making new functionality for the old database, but the problem is that all users already exist, and there is only one column with a password in the table with the user. Is it possible to somehow customize the framework user for a specific table?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-04-25
@WingRS

If the password in the old database is not hashed and stored in its original form, then pay attention
here:
www.yiiframework.com/doc-2.0/yii-base-security.html
and specifically on the generatePasswordHash() method.
Here are the methods for generating an authorization key and a hash password:

public function setPassword($password)
    {
        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
    }
    public function generateAuthKey()
    {
        $this->auth_key = Yii::$app->security->generateRandomString();
    }

That is, in fact, you can go through the old database and generate a new one with the desired password hash and authorization string, which, by the way, is just a set of random characters.

D
Dmitry, 2017-04-24
@slo_nik

Good evening.
The first option is to add your fields to the table.
The second option is to create a second table where all user data will be stored and link it to the first one by user id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question