<?phpApp::uses('AppModel','Model');/** * Users Model */classUsersextendsAppModel{.........publicfunctionbeforeSave($options=array()){parent::beforeSave($options);// Save new password is exist..?if(isset($this->data[$this->alias]['password'])==true){// Security bcrypt BlowfishApp::uses('Security','Utility');$hash=Security::hash(trim($this->data[$this->alias]['password']),'blowfish');$this->data[$this->alias]['password']=$hash;}returntrue;}publicfunctionpassword_check($user_id=null,$password_check=null){// Get password old$hash_old=$this->field('password',array('id'=>trim($user_id)));// Security bcrypt BlowfishApp::uses('Security','Utility');$hash_new_check=Security::hash(trim($password_check),'blowfish',trim($hash_old));// Son igualesif($hash_new_check==trim($hash_old)){returntrue;}returnfalse;}publicfunctionpassword_update($user_id=null,$password_new=null){// Update new passwordif($this->save(array('id'=>trim($user_id),'password'=>trim($password_new)))){returntrue;}returnfalse;}.........}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.