Welcome Guest, Not a member yet? Register   Sign In
What is wrong with this password update process?
#1

(This post was last modified: 03-04-2021, 06:00 AM by Ajax30.)

I am working on a basic blog application in Codeigniter 3.1.8 and Bootstrap 4.

I have added a registration and login system to this application. I am current working on a password reset system.

For a reason I have not been able to figure out, the password update process is flawed. I don't know if the issue is with the controller or the model.

In the controller I have:


PHP Code:
class Newpassword extends CI_Controller {
  private $token '';

    public function index($token) {
        $data $this->Static_model->get_static_data();
        $data['pages'] = $this->Pages_model->get_pages();
        $data['tagline'] = 'New password';
        $data['categories'] = $this->Categories_model->get_categories();
        $this->token $token;

        // Form validation rules
        $this->form_validation->set_rules('password''Password''required|min_length[6]');
        $this->form_validation->set_rules('cpassword''Confirm password''required|matches[password]');
        $this->form_validation->set_error_delimiters('<p class="error-message">''</p>');

     if(!$this->form_validation->run()) {
        $this->load->view('partials/header'$data);
        $this->load->view('auth/newpassword');
        $this->load->view('partials/footer');
     } else {
        $this->add();
     }
  }

  public function add() {
    $data $this->Static_model->get_static_data();
    $data['pages'] = $this->Pages_model->get_pages();
    $data['tagline'] = 'New password';
    $data['categories'] = $this->Categories_model->get_categories();

    // Encrypt new password
    $enc_password password_hash($this->input->post('password'), PASSWORD_DEFAULT);

    // Update password column
    $token $this->token;

    if ($this->Usermodel->set_new_password($token$enc_password)) {
      redirect('login'); 
      $this->session->set_flashdata("new_password_success""Your new password was set");
    } else {
        $this->session->set_flashdata("new_password_fail""We have failed updateing your password");
    }
  }


In the model:


PHP Code:
public function set_new_password($token$enc_password) {
        $this->db
            
->where(['token' => $token])
            // set new password and reset token to NULL
            ->update('authors', array('password' => $enc_password'token' => NULL));
    }


The form that is used to set the new password:


PHP Code:
<?php echo form_open(base_url('newpassword/add')); ?>
  <div class="form-group <?php if(form_error('password')) echo 'has-error';?>">
    <input type="password" name="password" id="password" class="form-control" placeholder="Password">
    <?php if(form_error('password')) echo form_error('password'); ?> 
  </div>
  <div class="form-group <?php if(form_error('cpassword')) echo 'has-error';?>">
    <input type="password" name="cpassword" id="cpassword" class="form-control" placeholder="Confirm password">
    <?php if(form_error('cpassword')) echo form_error('cpassword'); ?> 
  </div>
  <div class="form-group mb-2">
    <input type="submit" value="Set password" class="btn btn-block btn-md btn-success">
  </div>            
<?php echo form_close(); ?>


Where is my mistake?
Reply
#2

@Ajax30,

What error messages are you getting?
Reply
#3

(This post was last modified: 03-04-2021, 08:28 AM by Ajax30.)

(03-04-2021, 08:18 AM)php_rocs Wrote: @Ajax30,

What error messages are you getting?

No error message. Check the branch. Smile
Reply
#4

$token = ''
Reply
#5

(03-04-2021, 09:10 AM)iRedds Wrote: $token = ''

What line? What is wrong with it?
Reply
#6

PHP Code:
class Newpassword extends CI_Controller {
  private 
$token ''

You pass it to a method, but it's empty.

PHP Code:
// add()
    
$token $this->token;

    if (
$this->Usermodel->set_new_password($token$enc_password)) { 

PHP Code:
<?php echo form_open(base_url('newpassword/add')); ?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB