我有一个更改当前密码的表格。当我用新密码更新旧密码时,由于使用密码和盐安全性登录而无法登录,现在我不知道如何在更改密码时更改盐。
这是我的查看代码:
<div class="form-group">
<label class="col-sm-2 control-label">New Password <span class="required">*</span></label>
<div class="col-sm-10">
<input type="password" name="new_password" id="new_password" class="form-control" required />
<span class="error_message"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Confirm Password <span class="required">*</span></label>
<div class="col-sm-10">
<input type="password" name="confirm_password" id="confirm_password" class="form-control" required />
</div>
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-primary" type="submit" name="submit" value="submit">Submit</button>
</div>
</div>
控制器代码:
public function index() {
$this->admin_view('changepassword');
if ($this->input->post('submit')) {
$users_id = $this->session->userdata('users_id');
$new_pwd = md5($this->input->post('new_password'));
$change_password = $this->login_model->change_password($users_id,$new_pwd);
//print_r($new_pwd);exit();
if ($change_password) {
$this->session->set_flashdata('success_message', "'Password Changed.'");
$this->admin_view('changepassword');
}
}
}
型号代码:
public function change_password($id,$new_pwd){
$data = array('password' => $new_pwd);
$this->db->where('roles_id',$id);
$this->db->update('users', $data);
return true;
}