Authentication in User model

Dear All,

I have a model User extends CActiveRecord. It consists of ID, Username and Password fields.

  1. how could I check for duplicate on Username? if I tried to find the existing Username it is only work on new record, but update will always fails since it refers to itself. Any solution?

  2. I store the password in MD5 form in the MySQL. I used beforeSave() to change the format to MD5 for new record. How could I make sure that on update, it will not be changed to md5 again?

Thanks for the help.

Kind regards,

Daniel

  1. Why not use User::model()->exists(‘Username = :name’, array(’:name’ => $username)); ?

Details: http://www.yiiframework.com/doc/api/CActiveRecord#exists-detail

  1. Check this property: http://www.yiiframework.com/doc/api/CActiveRecord#isNewRecord-detail