Hash from some CakePHP2 field

-1

I created some tables with scaffold of CakePHP2, I have a model called account and I created a setter and getter:

public function setPassword($password)
{
    $this->password = Security::encrypt($password);
}

public function getpassword()
{
    return Security::encrypt($this->password);
}

Only the scaffold does not use these methods. How do I perform the hash of the field in both the insert and the view?

    
asked by anonymous 26.06.2018 / 16:23

1 answer

0

I suggested that you use beforeSave to change the values before they are saved , and then you can Security::encrypt() the password.

As far as I remember, CakePHP2 does not use getters / setters like this.

What do you need to do encrypt again when viewing? You'll already have the encrypted value after you make find , however, you can use afterFind to change the data as needed after the query.

    
26.06.2018 / 18:33