我是codeigniter的新手。我想更改密码并将其与旧密码匹配。如果匹配,则用户可以输入新密码。 我的视图文件是
<div class="modal-body">
<?php echo form_open('textarea/changePass')?>
<input class="span5" type="password" name="oldPass" placeholder="Old Password" required/>
<input class="span5" type="password" name="newPass" placeholder="New Password" required/>
<input class="span5" type="password" name="renewPass" placeholder="Re-type New Password" required/>
<input type="submit" value="Change" class="btn btn-primary btn-inverse" />
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
<?php echo form_close()?>
</div>
我的控制器文件是:
function changePass(){
$this->load->library('form_validation');
$this->form_validation->set_rules('oldPass','Old Password','required');
$this->form_validation->set_rules('newPass','New Password','required');
$this->form_validation->set_rules('renewPass','Retype Password','required|matches[newPass]');
if($this->form_validation->run() == FALSE){
$ref = $this->input->server('HTTP_REFERER', TRUE);
redirect($ref, 'location');
}else{
$query = $this->mod1->checkOldPass(md5($this->input->post('oldPass')));
echo "sdgsggs";
if($query){
$query = $this->mod1->saveNewPass(md5($this->input->post('newPass')));
if($query){
$this->session->sess_destroy();
$data['error']='Password Change Successfully. Please login to Continue.';
$this->load->view('first',$data);
}else{
$ref = $this->input->server('HTTP_REFERER', TRUE);
redirect($ref, 'location');
}
}
}
}
我的模型文件是:
function checkOldPass($oldPass){
$this->db->where('username',$this->session->userdata('username'));
$query=$this->db->get('members');
if($query->num_rows>0){
$row=$query->row();
if($oldPass == $row->password){
return true;
}else{
return false;
}
}
}
function saveNewPass($new_pass){
$data = array(
'password' => $new_pass
);
$this->db->where('username', $this->session->userdata('username'));
$query = $this->db->update('members', $data);
if($query){
return true;
}else{
return false;
}
}
我在检查旧密码时遇到问题。它返回假。我以md5格式保存了密码。请帮帮我们。请苛刻。谢谢。
答案 0 :(得分:0)
仅出于调试目的,请尝试以下操作:
function checkOldPass($oldPass){
$this->db->where('username', $this->session->userdata('username'));
$query=$this->db->get('members');
/* For debugging */
$row = $query->row();
echo "Old Password : ".$oldPass."<br>";
echo "From DB : ".$row->password."<br>";
die;
/* For debugging */
if($query->num_rows>0){
$row=$query->row();
if($oldPass == $row->password){
return true;
}else{
return false;
}
}
}