更改php / codeigniter中的密码 [英] changing password in php/codeigniter
本文介绍了更改php / codeigniter中的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个管理页面,用于创建帐户,删除帐户和更改用户密码。我有改变密码的编码的问题。下面我附上使用codeigniter创建的代码(旧密码不需要更改)
首页有这个:
工作人员名称:
新密码:
确认密码:
控制器文件。
<
<?php if(!defined('BASEPATH'))exit('不允许直接脚本访问);
class Admin extends MY_Controller {
public function index()
{
$ this-> load-> view('view-admin');
}
public function chgPassword()
{
$ query => $ this-> modeluser-> changpasswrd();
$ this-> load-> view('view-chg-password');
$ this-> view-chg-password-> set_rules('npassword','New Password','required | trim');
$ this-> view-chg-password-> set_rules('cpassword',
'Confirm Password','required | trim | matches [npassword]');
$ this-> session-> set_flashdata('message','< span class =label label-info>密码已更改!< / span>')
redirect(base_url()。'admin / chgpassword');
}
}
模型文件 / p>
<?php if(!define('BASEPATH'))exit('不允许直接脚本访问);
类ModelUser扩展CI_Model {
public function changpasswrd($ nama_staf,$ password){
$ this-> db-& ,$ password);
$ this-> db-> where('nama-staf',$ nama_staf);
$ this-> db-> update('akaun');
return $ this-> db-> affected_rows()> 0; }
函数DeleteUser($ options = array()){
//必需值
if(!$ this-> _required '),$ options))return false;
$ this-> db-> where('userId',$ options ['userId']);
$ this-> db-> delete('users'); }
$ b h2_lin>解决方案
您应该使用 form_validation 例如
$ this - > form_validation-> set_rules('npassword','New Password','required | trim');
$ this-> form_validation-> set_rules('cpassword','Confirm
Password','required | trim | matches [npassword]');
if($ this-> form_validation-> run()== FALSE){
$ this-> session-> set_flashdata('message',
'< span class =label label-info>错误!密码未更改!< / span>');
redirect(base_url()。'admin / chgpassword');
}
else {
$ query => $ this-> ModelUser-> changpasswrd($ this-> input-> post('nama-staf'),
$ this-> input-> post('npassword'))
$ this-> session-> set_flashdata('message',
'< span class =label label-info>密码已更改!< / span>')
redirect(base_url()。'admin / chgpassword');
}
代替
$ this-> view-chg-password-> set_rules('npassword','New Password','required | trim');
$ this-> view-chg-password-> set_rules('cpassword','Confirm Password',
'required | trim | matches [npassword]');
在中添加
like,构造函数
c $ c>控制器
public function __construct(){
parent: :__构造();
$ this-> load-> model('ModelUser');
}
i have created an admin page which is used to create account, delete account and change user password. i have problem with coding for changing password. below i attach codes created using codeigniter.(old password not required to change)
front page has this: staff name: new password: confirm password:
controller file.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends MY_Controller {
public function index()
{
$this->load->view('view-admin');
}
public function chgPassword()
{
$query => $this->modeluser->changpasswrd();
$this->load->view('view-chg-password');
$this->view-chg-password->set_rules(‘npassword’,'New Password’,'required|trim’);
$this->view-chg-password->set_rules(‘cpassword’,
'Confirm Password’,'required|trim|matches[npassword]‘);
$this->session->set_flashdata('message', '<span class="label label-info">Password changed!</span> ');
redirect(base_url().'admin/chgpassword');
}
}
model file.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ModelUser extends CI_Model {
public function changpasswrd($nama_staf, $password) {
$this->db->set('password', $password);
$this->db->where('nama-staf', $nama_staf);
$this->db->update('akaun');
return $this->db->affected_rows() > 0; }
function DeleteUser($options = array()) {
// required values
if(!$this->_required(array('userId'), $options)) return false;
$this->db->where('userId', $options['userId']);
$this->db->delete('users'); }
pls help me on this..
解决方案
You should use form_validation like
$this->form_validation->set_rules('npassword','New Password','required|trim');
$this->form_validation->set_rules('cpassword','Confirm
Password','required|trim|matches[npassword]');
if($this->form_validation->run() == FALSE){
$this->session->set_flashdata('message',
'<span class="label label-info">Error! Password not changed!</span>');
redirect(base_url().'admin/chgpassword');
}
else{
$query => $this->ModelUser->changpasswrd($this->input->post('nama-staf'),
$this->input->post('npassword'));
$this->session->set_flashdata('message',
'<span class="label label-info">Password changed!</span>');
redirect(base_url().'admin/chgpassword');
}
in place of
$this->view-chg-password->set_rules('npassword','New Password','required|trim');
$this->view-chg-password->set_rules('cpassword','Confirm Password',
'required|trim|matches[npassword]');
Add a construct function
in your controller
like,
public function __construct(){
parent::__construct();
$this->load->model('ModelUser');
}
Read form-validation()
这篇关于更改php / codeigniter中的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文