脚本宝典收集整理的这篇文章主要介绍了CakePHP $this-> Auth-> login()无效,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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','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()); */ } } } } }
正如您所看到的,我只是将用户名和密码插入$this-> Auth->登录,它无法正常工作!
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()); } }
谢谢!
原因1:$this-> Auth-> login以数据的形式获取数据
array( 'User'=>array( 'username'=>'myusername','password'=>'mypassword' ) )
原因2:$this-> Auth->登录不会对密码进行哈希处理.
在这种情况下,这条线路的所有可能性都不大可能:
您确定在最初创建用户名和密码时,是否设置了哈希值?
>要检查哈希匹配,请使用PHPmyadmin或MysqL workbench查看users表,并找到用户chris22的密码字段
>将该条目与当前哈希值进行比较.要检查当前的哈希值,请将代码放在控制器函数(索引)中的某个位置并在那里导航.
debug(Security::hash('stuff')); exit;
我希望这有帮助!
以上是脚本宝典为你收集整理的CakePHP $this-> Auth-> login()无效全部内容,希望文章能够帮你解决CakePHP $this-> Auth-> login()无效所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。