Sunday, 15 January 2012

php - CakePHP Login issue. and it doesnt work -



php - CakePHP Login issue. and it doesnt work -

i know there many questions on issue, i've tried add together resolutions still no luck far, sharing code see if can give me solution. thanks.

i've hashed password, added text field in password database won't have problem character amount. every time seek login, says invalid username/password, , doesn't redirect or anything. newbie in programming , php. please help.

here code:

appcontroller.php

app::uses('controller', 'controller'); class appcontroller extends controller { public $helpers = array('html', 'session', 'form' ); public $components = array( 'debugkit.toolbar', 'session', 'auth'=>array( 'loginredirect'=>array('controller'=>'user', 'action'=>'index'), 'logoutredirect'=>array('controller'=>'user', 'action'=>'index'), 'autherror'=>"you not allowed access page", 'authorize'=>array('controller') ) ); public function isauthorized($user){ homecoming true; } public function beforefilter() { $this->auth->allow('index', 'add'); } }

login.ctp

<h1> login form</h1> <?php echo $this->form->create('user'); echo $this->form->input('user_name'); echo $this->form->input('password'); echo $this->form->end(__('login')); ?>

user.php

// hash password before saving /* public function beforesave($options = array()) { $this->data['user']['password'] = authcomponent::password($this->data['user']['password']); homecoming true; } */ public function beforesave($options = array()) { if (isset($this->data['user']['password'])) { $this->data['user']['password'] = authcomponent::password($this->data['user'] ['password']); } homecoming true; } /** * primary key field * * @var string */ public $primarykey = 'user_id'; /** * display field * * @var string */ public $displayfield = 'user_name'; /** * validation rules * * @var array */ public $validate = array( //username validation 'username' => array( 'required' => array( 'rule' => array('minlength', 1), 'allowempty' => false, 'message' => 'please come in title.' ) ), 'user_name' => array( 'required' => array( 'rule' => array( 'isunique' ), 'message' => 'username exist. please seek again', //'allowempty' => false, //'required' => true, //'last' => true, // stop validation after rule //'on' => 'create', // limit validation 'create' or 'update' operations ), ), //email address validation 'email_address' => array( 'required' => array( 'rule' => array('minlength', 1), 'allowempty' => false, 'message' => 'please add together email' ) ), 'email_address' => array( 'required' => array( 'rule' => array( 'isunique' ), 'message' => 'email exist in our database. please seek again', //'allowempty' => false, //'required' => true, //'last' => true, // stop validation after rule //'on' => 'create', // limit validation 'create' or 'update' operations ), ), 'password'=>array( 'not empty' => array( 'rule'=>'notempty', 'message'=>'password empty' ), 'match passwords'=> array( 'rule'=>'matchpasswords', 'message'=>'password not match' ) ), 'password_confirmation'=>array( 'not empty' => array( 'rule'=>'notempty', 'message'=>'verify password' ) ) ); // password confirmation validation function public function matchpasswords($data){ if ($data['password'] == $this->data['user']['password_confirmation']) { homecoming true; } $this->invalidate('password_confirmation', 'your password not match'); homecoming false; } }

php cakephp

No comments:

Post a Comment