cakePHP使用关联数据进行身份验证

时间:2017-05-10 04:07:29

标签: php cakephp cakephp-3.0

电子邮件表有:id,地址。 Users表有id,email_id,密码(哈希)

如何使用此身份验证登录。

'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'address',
                    'password' => 'password',
                ],
                'userModel' => 'Users'
            ]
  ]

然后在login()中调用:

$user = $this->Auth->identify();
if($user){
 //success }

我不确定这是否是我需要的,或者它如何处理这个来验证

public function findAuth(\Cake\ORM\Query $query, array $options){
    select(['Emails.address', 'password'])
        ->where(['Emails.address' => $options['address']]);

设置密码是这样的:

protected function _setPassword($
    if(strlen($pw) > 0){
        return  (new DefaultPasswordHasher)->hash($pw);
    }   }

fyi注册的工作原理如下:

if($this->Users->save($user))

我的表格是

This form control (emails.address)
This form control (password)

0 个答案:

没有答案