E
E
enchikiben2012-06-30 21:13:12
Yii
enchikiben, 2012-06-30 21:13:12

Updating user password in Yii

Good evening!
Tell me how to make sure that when updating a user's record, his password does not change. there is md5, and where is it better to encrypt it in md5 when registering / changing a password, I do this in beforeSave, but I ran into a problem that when editing a record, the existing hash is again hashed.

Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
p4s8x, 2012-06-30
@EnChikiben

In "pure" yii, there is no db-authorization. Most likely you are using either some kind of skeleton (assembly) or an extension.
You need to look at UserIdenity, WebUser, but first of all, the code of the model, such as user.

B
balloon, 2012-07-01
@balloon

public function beforeSave() {
  if ($this->isNewRecord)
     $this->password = md5($this->password);
  return parent::beforeSave();
}

A
Alexey Prokhorov, 2012-07-01
@megahertz

Years of practice with Yii has shown that putting code that changes data in beforeSave should only be done when absolutely necessary. In most cases, it is better to move the code into a separate method and call it from the controller - and such problems do not arise, and it is easier to understand the code later. Also, if you have to change field data before saving / retrieving, it is often easier to spend time creating a form, rather than working directly through the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question