cakePHP 2.0のAuthコンポーネントでパスワードの暗号化を無効にする

cakePHP2.0でAuthコンポーネントを使おうとしてみたのだが、認証の際、パスワードを暗号化するのが前提となっている模様。
今回やるのは必要ないので、なんとかはずす方法ないかなと探ってみたが

[CakePHP]AuthComponentのパスワード暗号化を無効にする方法

この辺、1.2や1.3の情報らしく、同じようにやってもうまくいかない。2.0でコンポーネントのコードが大分変わった模様。
で、よくよくコード見てみると、パスワードの暗号化は、

BaseAuthenticateクラスの


/**
* Hash the plain text password so that it matches the hashed/encrytped password
* in the datasource.
*
* @param string $password The plain text password.
* @return string The hashed form of the password.
*/
protected function _password($password) {
return Security::hash($password, null, true);
}

この部分で行ってる模様。ここをreturn $passwordとするようにすれば、OKっぽかったので、

app/Controller/Component/Auth

に以下のようなクラスを作成して


App::uses('FormAuthenticate', 'Controller/Component/Auth');

class MyFormAuthenticate extends FormAuthenticate {

protected function _password($password){
return $password;
}

}

呼び出し側で


public $components = array('Auth'=>
array('authenticate'=>array('MyForm'));

こんな感じに記述するとうまく動いた。

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>