Since few days, almost one week, i have an issue, to compare passwords in cakephp.
I'm preparing edit user view, and befor user will be able to change his current password he needs to type his old password. ( i'm extending authorization tutorial from cakebook.)
While user is creating his password is hashing in User.php (Model)
public function beforeSave($options = array()) {
{
if(isset($this->data[$this->alias]['password']))
{
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
i tried compare field old_password after AuthComponent with ( any way to receive user pass) like $this->Session->read('Auth.User.password'), but ofcourse it fails, i tried to send old_password and hash it in model User.php, also i created in this model
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel
{
public $validate = array(
'username'=>array(
'required'=>array(
'rule'=>array('notEmpty'),
'message'=>'Write correct Login'
)
),
'password'=>array(
'required'=>array(
'rule'=>array('notEmpty'),
'message'=>'Please re-enter your password twice so that the values match'
)
),
'old_password'=>array(
'required'=>array(
'rule'=>array('equalTo'=>'password'),
'message'=>'Wrong'
)
)
);
with using different ways of 'equalTo',password or 'equalTo','password'
i also tried to compare old_password input with database one in edit.ctp, but all my works fails.
please give me some tip.
EDIT (becouse of my low reputation i can;t answer my own post before 8 hours after asking so i edit this part to)
Anil Kumar You gave me good advice. I fallow your way, but An Internal Error Has Occurred.
Error: An Internal Error Has Occurred.
every time, i change this part of code on my way, as fallows, and it perfectly works, ofcourse thanks to You Anil Kumar.
public function password_verifies()
{
//$this->User->id = $this->data[$this->alias]['id'];
//return AuthComponent::password($this->data[$this->alias]['password']) == $this->User->field('password');
$od = AuthComponent::password($this->data['User']['old_password']);
if($od == $this->field('password'))
{
return true;
}
return false;
}
currentto true. - mark