0

I was hoping to get Cake PHP 2.x's field type mapping to change password field from a salted SHA1 hash into a varchar field, to UNHEX('$hash') in SQL, so I can store the password in the binary(20) field.

For anyone questioning why I'm doing it this way: Storing SHA1 hash values in MySQL

Currently I see no way around it than to do my own $this->User->query("INSERT INTO....");, and it would be nice to do it the cake way.

Any advise would be great!

Cheers!

Community
  • 1
  • 1
PC_Nerd
  • 23
  • 5

1 Answers1

0

you can try this:

public function beforeSave() {
    if (isset($this->data[$this->alias]['password'])) {
    $this->data[$this->alias]['password'] = DboSource::expression('UNHEX('. $this->data[$this->alias]['password'].')');
    $this->data[$this->alias]['test'] = 'hello';
    }
    return true;
}
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164