您好我正在尝试为用户控制面板创建用户更改密码功能,我发现这里有一些尝试编辑但我遇到了一些问题。
这是控制器部分
public function ucp_change_pass() {
$data2['title'] = "Change Password";
$data = new stdClass();
$this->form_validation->set_rules('old_password', 'Old Password', 'trim|required|min_length[4]');
$this->form_validation->set_rules('new_password', 'New Password', 'trim|required|min_length[4]');
$this->form_validation->set_rules('new_password_confirm', 'Old Password', 'trim|required|min_length[4]|matches[new_password]');
if ($this->form_validation->run() === false) {
$this->load->view('header', $data2);
$this->load->view('ucp/ucp_menu');
$this->load->view('ucp/ucp_change_pass', $data);
$this->load->view('footer');
} else {
$old_password = $this->input->post('old_password');
$new_password_confirm = $this->input->post('new_password_confirm');
$query = $this->Home_model->checkOldPass($old_password);
if($query){
$query = $this->Home_model->saveNewPass($new_password_confirm);
if($query){
redirect('./ucp_change_pass_success');
}else{
redirect('./ucp_change_pass');
}
}
}
}
这是模型部分
public function checkOldPass($old_password){
$this->db->where('username', $this->session->userdata('username'));
$query = $this->db->get('users');
$row = $query->row();
echo "Old Password : ".$this->hash_password($old_password)."<br>";
echo "From DB : ".$row->password."<br>";
die;
if($query->num_rows > 0){
$row = $query->row();
if($old_password == $row->password){
return true;
}else{
return false;
}
}
}
public function saveNewPass($new_password_confirm){
$array = array(
'password'=>$this->hash_password($new_password_confirm)
);
$this->db->where('username', $this->session->userdata('username'));
$query = $this->db->update('users');
if($query){
return true;
}else{
return false;
}
}
这是视图
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<?php
if (isset($_SESSION['logged_in']) != TRUE) {
echo redirect('/login');
}
?>
<div class="col-md-9">
<div class="list-group">
<div class="list-group-item ucp-nav-bar">User Control Panel</div>
<div class="list-group-item">
<?= form_open() ?>
<div class="form-group">
<label for="name">Old Password</label>
<input type="password" class="form-control" id="old_password" name="old_password" placeholder="Enter your current password">
</div>
<div class="form-group">
<label for="email">New Password</label>
<input type="password" class="form-control" id="new_password" name="new_password" placeholder="Enter a new password">
</div>
<div class="form-group">
<label for="message">New Password Confrim</label>
<input type="password" class="form-control" id="new_password_confirm" name="new_password_confirm" placeholder="Re-enter the new password for confirmation">
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" value="Change Password">
</div>
</form>
我遇到的问题是,当我提交输入时,使用hash_password加密的旧密码与数据库中的密码不同。 数据库中的密码使用hash_password加密。
这是模型中的hash_password函数
答案 0 :(得分:0)
您需要解密控制器中的$ old_password。像这样改变你的控制器的其他部分。
HTTP Status 405 - Request method 'POST' not supported in jmeter
您需要加密旧密码,然后将其传递给模型。