Tuesday 8 March 2016

How to change user password in CakePhp using Auth


cakephp.jpg

Hi All,
In this blog we will discuss how to change the password in cakePhp by using Auth.
Firstly, in your model you have to define a function beforeSave which will hash your password to auth password, you can do this by writing the below code:

  1. public function beforeSave($options = array()) {

  2.       if (isset($this->data[$this->alias]['password'])) {

  3.       $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
  4.       }
  5.       return true;
  6.   }
In your change Password function you have to write-
  1.   public function changePassword() {

  2.       if ($this->data) {
  3.           if (!empty($this->data['User']['password']) && !empty($this->data['User']['repassword'])) {
Read full blog about How to change user password in CakePhp using Auth visit Findnerd.

No comments:

Post a Comment