0

我正在运行 cakephp 2.6 和 xamp 网络服务器,我试图让 Digest Auth 与 cakephp 一起工作。

当我使用它时,它会一遍又一遍地询问用户名和密码。我不确定出了什么问题或如何解决这个问题。我没有找到关于如何在 cakephp 中使用摘要身份验证的教程。

我已经按照 cakephp 手册中的指南进行操作;

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

应用控制器;

public $components=array(
'Session',  'Security',
'Auth'=>array(
    'loginRedirect'=>array('controller'=>'users','action'=>'index'),
    'logoutRedirect'=>array('controller'=>'users','action'=>'index'),
    'authError'=>'Access Denied: You are not authorized to view that page.',
    'authorize'=>array('Controller'),       
    'authenticate' => array('Digest')
    )
);

有什么想法有什么问题吗?

4

1 回答 1

0

我没有以“蛋糕”的方式尝试过,但是在我的应用程序控制器中(在 beforeFilter() 中)有这个代码对我有用。

        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header('WWW-Authenticate: Basic realm="Your Realm"');
            header('HTTP/1.0 401 Unauthorized');
            echo 'Ops!! Smth wrong';
            exit;
        } else {
            $hash = 'sha512 hash of your password with cakes salt';
            if ($_SERVER['PHP_AUTH_USER'] == 'your_username' && Security::hash($_SERVER['PHP_AUTH_PW'], 'sha512', true) == $hash) {
                ;
            } else {
                header('WWW-Authenticate: Basic realm="Your Realm"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Ops!! Smth wrong';
                exit;
            }
        }
于 2015-03-27T15:23:49.997 回答