Beforesave/aftervalidate Alternative

Hello, I am having a little problem finding alternatives for beforeSave/afterValidate, basically I need to hash passwords before user creates his/her account (I am using afterValidate for this), it all works fine, however, when user wants to update his/her account (e.g. insert First/Last names etc.) the password changes as afterValidate kicks in every time before I save() model. Is there any alternative to hash password before saving record, but not using afterValidate or beforeSave?

There is one solution for that.

While updating record, Check if the password field is empty then don’t make md5 of that string if not empty then take new string as new password and make md5 of that string and update in Database. For that you can use setAttribute() function of YII for storing password.

While updating a record, give password field empty by default and if user wants to change password then he will insert text if not then user will keep it empty.


Below link can help you to solve your problem

khush@l, much appreciated, very fast reply, easy implementation, works perfectly =]

Its my pleasure!!!

Cheers… :)