すべからくパスワードはDB保存時にハッシュ化されるべきですが、
http://book.cakephp.org/2.0/ja/tutorials-and-examples/blog-auth-example/auth.html
を参考にUserモデルのファイルに、
// hashing password
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
return true;
}
と、ルーチンを追加して、保存時にハッシュ化されるように設定。このままだと、passwordフィールドを含まない更新でエラーが発生するので、
下記のように書き換える。
// hashing password
public function beforeSave($options = array()) {
if ( isset ( $this->data['User']['password'] ) ) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
}
return true;
}
こうすれば、パスワードに触れずに、その他のフィールドをeditする事が可能。2.4以降では、ハッシュ化もモジュールを通じて行われるようです。上記問題も対応済です。
http://book.cakephp.org/2.0/ja/tutorials-and-examples/blog-auth-example/auth.html
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash($this->data[$this->alias]['password']);
}
return true;
}