蛋糕php ---密码哈希

时间:2014-01-02 10:13:42

标签: php cakephp

我在我的控制器中使用它

public $components = array(`enter code here`
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => array(
                        'className' => 'Simple',
                        'hashType' => 'sha256'
                    )
                )
            )
        )
    );

这是从书中提到的:http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

这在我的模型中

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

class User extends AppModel {
    public function beforeSave($options = array()) {
        if (!$this->id) {
            $passwordHasher = new SimplePasswordHasher();
            $this->data['User']['password'] = $passwordHasher->hash(
                $this->data['User']['password']
            );
        }
        return true;
    }
}

1 个答案:

答案 0 :(得分:0)

使用它来散列密码:

$this->data['User']['password'] = 
    AuthComponent::password($this->data['User']['password']);

由于AuthComponent :: password()随处可见。

至少如果这是你要求的。同意Shankar,这个问题不见了。