php - Codeigniter Form Validation Rule for match (password) -
i trying write form validation rules in controller submit change password form in checking old password too. getting old password(current) db , placing in hidden input field.
my rules simple , given below
$config=array( array( 'field' => 'old_password', 'label' => 'oldpass', 'rules' => 'trim|required' ), array( 'field' => 'conf_password', 'label' => 'connewpass', 'rules' => 'trim|required|matches[password]' ), array( 'field' => 'password', 'label' => 'newpass', 'rules' => 'trim|required' )
my hidden input field in form save current password
<input type="hidden" name="old_pass" value="<?php echo $user['password']?>">
i know matches(field name) in rules work matching 2 field values stuck password coming db md5 encrypted. how can encrypt password coming form , match old pass field in rule?
there no need of putting old password hash in hidden field. it's not safe. can create callback function own custom validation. notice comment have did in following code.
$config=array( array( 'field' => 'old_password', 'label' => 'oldpass', 'rules' => 'trim|required|callback_oldpassword_check' // note: notice added callback verifier. ), array( 'field' => 'conf_password', 'label' => 'connewpass', 'rules' => 'trim|required|matches[password]' ), array( 'field' => 'password', 'label' => 'newpass', 'rules' => 'trim|required' )
in side controller create method below
public function oldpassword_check($old_password){ $old_password_hash = md5($old_password); $old_password_db_hash = $this->yourmodel->fetchpasswordhashfromdb(); if($old_password_hash != $old_password_db_hash) { $this->form_validation->set_message('oldpassword_check', 'old password not match'); return false; } return true; }
for more details of callback verification visit here
i have not verified above code. hope way solve problem.
Comments
Post a Comment