【发布时间】:2017-06-26 19:20:00
【问题描述】:
我尝试使用 cakephp 3 的摘要认证来构建一个可扩展的系统。仅在需要时要求客户端输入密码,但输入的详细信息不允许访问,而是再次弹出请求凭据的对话框。非常感谢任何建议或帮助!
AppController::initialize()
$this->loadComponent('Auth', [
'authenticate' => [
'Digest' => [
'fields' => ['username' => 'username', 'password' => 'password_hash'],
'userModel' => 'Users',
'finder' => 'auth'
],
],
'authError' => 'incorrect username or password',
'storage' => 'Memory',
'unauthorizedRedirect' => false
]);
用户表:
public function beforeSave(\Cake\Event\Event $event)
{
$entity = $event->data['entity'];
// Make a password for digest auth.
$entity->password_hash = DigestAuthenticate::password(
$entity->username,
$entity->plain_password,
env('SERVER_NAME')
);
$entity->created = Time::now();
return true;
}
public function findAuth(\Cake\ORM\Query $query, array $options)
{
$query
->select(['id', 'username', 'password_hash']);
return $query;
}
编辑:从实体中删除代码
我决定深入研究摘要 getuser 函数 (Function code) 并将一些数据输出到我未经授权的页面中,以便查看发生了什么。
$Password: 8a3575d301f04f08dd461f93e3d55a21
$digest[username]: James
$digest['response']: 4fa261678c753da8e78e4bf98057fd72
$hash: a627c3e68061937e454c321d55e986d3
$request->env('ORIGINAL_REQUEST_METHOD'): GET
【问题讨论】:
标签: authentication cakephp cakephp-3.0 stateless digest-authentication