Welcome Guest, Not a member yet? Register   Sign In
Mythauth - update password form
#1

Hey all,

I have the following problem: I have created a form with which the user should be able to update his password.
When the new password is entered and submitted, the "password_hash" field in the database table "users" is updated. However, I cannot log in with the new password afterwards.

Does anyone have any idea what my mistake is?


My current code:


Code:
namespace App\Models;
use CodeIgniter\Model;

class User_Model extends Model {

    protected $table = 'users';
    protected $primaryKey = 'id';

    protected $allowedFields = ['id','password_hash','updated_at'];        

}

Code:
/**
UPDATE FUNCTION IN THE CONTROLLER
**/

public function updatePassword() {
  $model = new User_Model();

  //Costs for the creation of the password hash.
  $hashOptions = [
      'cost' => 5,
  ];

  //Get input and hash password
  $password = $this->request->getPost('new-password');
  $hashed_password = password_hash(base64_encode(hash('sha384', $password, true)),PASSWORD_DEFAULT,$hashOptions);

  //Get id of current user
  $user_id = user_id();

  //Get current timestamp for updated_at field in the record
  $updated_at = date('c', time());

  //Create data array for the update of the record
  $data = [
      'password_hash' => $hashed_password,
      'updated_at' => $updated_at
  ];

  //Update the record
  $model->update($user_id,$data);
}

Code:
<form action="<?php echo base_url('Security_Settings_Controller/updatePassword'); ?>" method="post">
  <?= csrf_field() ?>
   <div class="form-group">
       <label for="old-password">Old Password</label>
       <input class="form-control" id="old-password" type="password">
   </div>
   <div class="form-group">
      <label for="new-password">New Password</label>
      <input class="form-control" id="new-password" type="password">
   </div>
   <div class="form-group">
      <label for="confirm-new-password">Confirm Password</label>
      <input class="form-control" id="confirm-new-password" type="password">
   </div>
   <button class="btn btn-primary btn-block" type="submit">Update Password</button>
</form>
Reply


Messages In This Thread
Mythauth - update password form - by schwaluck - 03-21-2021, 08:02 AM
RE: Mythauth - update password form - by InsiteFX - 03-21-2021, 08:49 PM
RE: Mythauth - update password form - by InsiteFX - 03-22-2021, 10:43 AM
RE: Mythauth - update password form - by ikesela - 03-22-2021, 10:37 PM
RE: Mythauth - update password form - by fuzna28 - 03-31-2021, 08:49 AM
RE: Mythauth - update password form - by fuzna28 - 04-02-2021, 06:43 AM
RE: Mythauth - update password form - by kilishan - 06-21-2021, 07:09 AM
RE: Mythauth - update password form - by ikesela - 06-21-2021, 07:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB