CakePHP 2.0 - Able to Register, but cannot login -
im cakephp newbie, apologies if question has been asked search not find. have problem code below. works when register new user, problem when im trying login , error "invalid username or password'); please help
public function login() { if ($this->request->is('post')) { if ((!empty($this->request->data['user']) && $this->auth->login())) { $this->session->setflash(__('welcome, '. $this->auth->user('username'))); $this->redirect($this->auth->redirecturl()); } else { $this->session->setflash(__('invalid username or password')); } } }
//******* login ctp************
<div class="users form"> <?php echo $this->session->flash('auth'); ?> <?php echo $this->form->create('user'); ?> <fieldset> <legend><?php echo __('please enter username , password'); ?></legend> <?php echo $this->form->input('username'); echo $this->form->input('password'); ?> </fieldset> <?php echo $this->form->end(__('login')); ?>
//*******************before save *************************
public function beforesave($options = array()) { // hash our password if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = authcomponent::password($this->data[$this->alias]['password']); } // if new password, hash if (isset($this->data[$this->alias]['password_update']) && !empty($this->data[$this->alias]['password_update'])) { $this->data[$this->alias]['password'] = authcomponent::password($this->data[$this->alias]['password_update']); } // fallback our parent return parent::beforesave($options); }
Comments
Post a Comment