2011-01-27 38 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回调方法重置密码