2011-01-27 41 views
1

我有一個notEmpty驗證規則設置爲我的密碼字段。問題是,AuthComponent自動散列字符串。因此,如果密碼爲空,它將在驗證之前變成散列,以便散列時它不會爲空,但實際的純文本密碼爲空。CakePHP AuthComponent哈希空字符串導致notEmpty驗證問題

我能想到的最佳解決方案是使AuthComponent不會散列空字符串。誰能告訴我該怎麼做?或更好的解決方案?

回答

2

一個想法:

public function beforeValidate() { 
    App::import('Core', 'Security'); // not sure whether this is necessary 
    if ($this->data['User']['password'] == Security::hash('', null, true)) { 
     $this->data['User']['password'] = ''; 
    } 
    return true; 
} 
:你可以像你的用戶模型的 beforeValidate回調方法重置密碼