Dob*_*ler 3 authentication cakephp cakephp-1.3
除了auth手动调用之外,Web应用程序运行良好.几天来我一直在努力奋斗.在我的示例代码中,我暂时重写了cookie以缩小原因.这是我的app控制器剪辑:
App::import('Sanitize');
//uses('sanitize');
class AppController extends Controller {
var $components = array('Clean','Acl', 'Auth', 'Session', 'RequestHandler', 'Cookie', /* 'DebugKit.Toolbar' */);
var $helpers = array('uiNav','Flash','Html', 'Form', 'Session','Javascript','Ajax','Js' => array('Jquery'), 'Time','Js');
function beforeFilter() {
//Configure AuthComponent
$this->Auth->authorize = 'actions';
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'view');
$this->Auth->actionPath = 'controllers/';
$this->Auth->autoRedirect = false;
$this->Auth->allowedActions = array('display');
if(!$this->Auth->user()){
//$cookie = $this->Cookie->read('Auth.User');
$cookie = array('username' => 'chris22', 'password' => 'stuff');
if (!is_null($cookie)) {
$this->set('checking_cookie',$cookie);
if ($this->Auth->login($cookie)) {
$this->set('cookie_message','cookie validates!');
// Clear auth message, just in case we use it.
$this->Session->delete('Message.auth');
/* $this->redirect($this->Auth->redirect()); */
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我只是将用户名和密码插入$ this-> Auth-> login并且它无法正常工作!
我不知道我的用户控制器是否相关,但这里也是登录功能:
function login() {
if ($this->Auth->user()) {
if (!empty($this->data) && $this->data['User']['remember_me'] && isset($this->data['User']['password'])) {
$cookie = array();
$cookie['username'] = $this->data['User']['username'];
$cookie['password'] = $this->data['User']['password'];
$this->Cookie->write('Auth.User', $cookie, true, '+1 month');
//unset($this->data['User']['remember_me']);
$this->set('cookie-00', 'setting cookie.');
}else{ $this->set('cookie_message', 'not setting cookie.');}
$this->redirect($this->Auth->redirect());
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑 - 1 - 我想我知道为什么这不适合你.
原因1:$ this-> Auth-> login以数据的形式获取数据
array(
'User'=>array(
'username'=>'myusername',
'password'=>'mypassword'
)
)
Run Code Online (Sandbox Code Playgroud)
原因2:$ this-> Auth-> login不会对密码进行哈希处理.
您必须完全按照数据库中显示的密码发送密码.
在这种情况下,这条线路的所有可能性都不大可能:
您确定在最初创建用户名和密码时,是否设置了哈希值?
将该条目与当前哈希值进行比较.要检查当前的哈希值,请将代码放在控制器函数(索引)中的某处,然后在那里导航.
debug(Security::hash('stuff'));
exit;
Run Code Online (Sandbox Code Playgroud)我希望这有帮助!