I have confuse where should I md5 the password. If I put it on the beforeSave() on the User model, I will have a problem when updating the module, the already md5 password will be md5 again. At the moment, I put a check on the beforeSave() so that the password with length = 32 will not be md5 again. The only drawback with this solution is that the user cannot have a password with exactly 32 characters.
Thanks for the advice. I will try to look at the sha1. Which one is better, double hashing or random salt? However, random salt key should be stored somewhere since I need to match the password when the user is login.
You can add property newPassword to your model. The corresponding field should appear in an update form. In your rules() you should define it “safe” for “update” scenario (‘on’=>‘update’). In the beforeSave() method just check it for emptyness (if not empty, then $this->password = md5($this->newPassword)).
Double hashing or simple salt don’t give a very big additional security. If users type the same passwords, they will still hash to the same value (not good at all). And yes, you will need one more field in the database to store randomly generated salt (CHAR(16) should be enough).