Skip to content

Instantly share code, notes, and snippets.

@arvindravi
Created December 9, 2011 10:10
Show Gist options
  • Save arvindravi/1450979 to your computer and use it in GitHub Desktop.
Save arvindravi/1450979 to your computer and use it in GitHub Desktop.
Password Change module - CI
My View
<form action="" method="POST" id="pwdchange">
<span><h2 style="font-family:'Ubuntu',sans-serif;" align="justify">Change your Password here</h2><br /></span>
<?php echo form_open('users/passwordchange');?>
Current Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php $data=array('id'=>'oldpwd','name'=>'oldpwd','class'=>'span4','type'=>'password','placeholder'=>'Old Password');
echo form_input($data); ?><br /><br />
New Password:
<?php $data2=array('id'=>'newpwd','name'=>'newpwd','class'=>'span4','type'=>'password','placeholder'=>'New Password');
echo form_input($data2); ?><br /><br />
Password:
<input type="submit" class="btn primary large" style="font-family:'Ubuntu',sans-serif;" id="submitbtn" value="Change my Password"></input>
<?=form_close();?>
</form>
My Controller
public function passwordchange()
{
$this->load->model('users');
$oldpwd = $this->input->post('oldpwd');
$newpwd = $this->input->post('newpwd');
$flag = $this->users->pwdchange($oldpwd,$newpwd);
if($flag == TRUE)
{
echo "password changed";
}
else
{
echo "failed";
}
}
My Model
public function pwdchange($oldpwd,$newpwd)
{
$this->load->database();
if(md5($oldpwd) == $this->session->userdata('password'))
{
$npwd = md5($newpwd);
$data = array('password' = $npwd);
$uid = $this->session->userdata('id');
$this->db->where('id', $uid);
$this->db->update->('users',$data);
return true;
}
else
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment