Forgot password using codeigniter

Controller:-

public function change_pass()
{
   if($this->input->post('change_pass'))
    {
        $old_pass=$this->input->post('old_pass');
        $new_pass=$this->input->post('new_pass');
        $confirm_pass=$this->input->post('confirm_pass');
        $session_id=$this->session->userdata('id');
        $que=$this->db->query("select * from user where id='$session_id'");
        $row=$que->row();
        if ($old_pass == $confirm_pass && $old_pass == $new_pass)
     {
          $this->session->set_flashdata('error','Wrong Old Password and New Password in password combination.');
            redirect('/Profiles/change_pass');
     }
    elseif ($new_pass == $confirm_pass)
     {
        $this->profile->change_pass($session_id,$new_pass);
        $this->session->set_userdata('success_msg', 'Password has been Update successfully.');
        redirect('/Profiles/profile_view');
     }
     elseif ($new_pass != $confirm_pass)
     {
        $this->session->set_flashdata('error','Wrong New Password and Confirm Password in password combination.');
        redirect('/Profiles/change_pass');
     }

     else{

     }
}
        $this->load->view('templates/header', $data);
        $this->load->view('templates/nav', $data);
        $this->load->view('Profiles/add-edit', $data);
        //$this->load->view('templates/footer');     
}

Model:-

function change_pass($session_id,$new_pass)
{
$update_pass=$this->db->query("UPDATE user set password='$new_pass' where id='$session_id'");
}

View:-

<section class="content-header">
      <h1>
        Reset Password
        <small>Control panel</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        <li class="active"> Reset Password</li>
      </ol>
    </section>
<div class="container">
    <?php if(!empty($success_msg)){ ?>
    <div class="col-xs-10">
        <div class="alert alert-success"><?php echo $success_msg; ?></div>
    </div>
    <?php }elseif(!empty($error_msg)){ ?>
    <div class="col-xs-10">
        <div class="alert alert-danger"><?php echo $error_msg; ?></div>
    </div>
    <?php } ?>
    <div class="row">
        <div class="col-xs-6">
<div id="error_text" style="color:red"><?php echo $this->session->flashdata('error'); ?></div>
            <div class="panel panel-default">
                <div class="panel-heading"><?php echo $action; ?> Reset Password<a href="<?php echo site_url('Profiles/profile_view'); ?>" class="glyphicon glyphicon-arrow-left pull-right">GoView</a></div>
                <div class="panel-body">
                    <form method="post" action="" class="form">
                         <div class="form-group">
                            <input type="text" name="old_pass" id="name" class="form-control"  placeholder="Old Password" value="<?php echo !empty($post['password'])?$post['password']:''; ?>" required minlength="6" maxlength="6">
                            <?php echo form_error('old_pass','<p class="help-block text-danger">','</p>'); ?>
                            </div> 
                             <div class="form-group">
                            <input type="password" name="new_pass" id="password" placeholder="New Password" class="form-control"  value="<?php echo !empty($post['password'])?$post['password']:''; ?>" required minlength="6" maxlength="15">
                            <?php echo form_error('new_pass','<p class="help-block text-danger">','</p>'); ?>
                            </div>
                             <div class="form-group">
                            <input type="password" name="confirm_pass" id="password" placeholder="Confirm Password" class="form-control" value="<?php echo !empty($post['password'])?$post['password']:''; ?>" required minlength="6" maxlength="15">
                            <?php echo form_error('confirm_pass','<p class="help-block text-danger">','</p>'); ?>
                            </div>
                        <input type="submit" value="Submit" name="change_pass" class="btn btn-primary" value="Submit"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




Comments

Popular posts from this blog

Insert and Update or Edit Data using jQuery Dialogify with PHP Ajax

Facebook Login With Codeigniter