cakephp - Auth->login() function not working properly -


here's component declaration in appcontroller.php>

'auth' => array(     'authenticate' => array(         'form' => array(             'usermodel' => 'user',             'fields' => array('username' => 'email', 'password' => 'code'),             'scope' => array('activated' => true),         ),     ),     'loginaction' => array('controller' => 'users', 'action' => 'login'),     'loginredirect' => array('controller' => 'members', 'action' => 'dashboard', 'admin' => true),     'autherror' => 'no permission',     'logoutredirect' => array('controller' => 'pages', 'action' => 'home'),     'userscope' => array('user.activated' => true), ), 

the login form:

<?= $this->form->create('user', array('url' => '/users/login', 'class' => 'form-inline'));?>     <div class="form-group">         <?= $this->form->input('user.email', array(             'div' => false,             'label' => false,             'placeholder' => 'е-пошта',             'class' => 'form-control',             'required' => true,         ));?>         <?= $this->form->input('user.code', array(             'div' => false,             'label' => false,             'placeholder' => 'сериски број',             'class' => 'form-control',             'required' => true,         ));?>         <?= $this->form->button('<i class="fa fa-user"></i>', array('type' => 'submit', 'class' => 'btn btn-primary', 'escape' => false));?>     </div> <?= $this->form->end();?> 

and snippet of login function:

// ... if($this->request->is('post')) {     if($this->auth->login()) {         if(isset($this->request->data['user']['token']) && $this->request->data['user']['token']) {             $token = substr(md5(time()), 0, 32);             $this->user->id = $this->auth->user('id');             $this->user->savefield('token', $token);             $this->cookie->write('remember_me', $token, false, '1 week');         }         return $this->redirect($this->auth->loginredirect);     }     // ... 

now, when use $this->auth->login($this->request->data) or $this->auth->login($this->request->data['user']), works, when use $this->auth->login() doesn't. can workaround logging in $this->request->data , putting rest of user data manually available afterwards, want know why happens. ideas?

edit

so, karthik keyan mentioned hashing, figured problem. cakephp automatically hashing password (code field) , didn't want to. made custom hasher class named nopasswordhasher follows:

app::uses('abstractpasswordhasher', 'controller/component/auth');  class nopasswordhasher extends abstractpasswordhasher {     public function hash($password) {         return $password;     }      public function check($password, $hashedpassword) {         return $password == $hashedpassword;     } } 

and used in auth component:

'auth' => array(     'authenticate' => array(         'form' => array(             'usermodel' => 'user',             'fields' => array('username' => 'email', 'password' => 'code'),             'scope' => array('activated' => true),             'passwordhasher' => 'no',         ),     ), 

it works now. thank you.

tell type of errors can display you.please check can store password in hash (salt) format.


Comments