php - insert hashed password while register in codeigniter
I have user pannel in a codeigniter. where user have a option to register. i want to user's password to hashed in my database. i have done the registeration with normal password but i want now password to be hashed. I have taken help with similar questions but resulted into an error
controller
public function signupvalidation()
{
$this->load->library('form_validation');
if($this->form_validation->run('userregister'))
{
$post = $this->input->post();
$this->load->model('userregister');
if($this->userregister->register1($post))
{
echo "insert succesfully";
}
else
{
echo "not succesfully";
}
$this->session->set_flashdata('insertsuccess','User Registration Successfully');
return redirect('user/signup');
}
else
{
$this->load->view('user/usersignup');
}
}
model
private function hash_password($password){
return password_hash($password, PASSWORD_BCRYPT);
}
public function register1($name,$email,$password){
$data = array(
'name' => $name,
'email' => $email,
'password' => $this->hash_password($password)
);
return $this->db->insert('user', $data);
}
the error i have got
An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function userregister::register1(), 1 passed in C:\xampp\htdocs\blog\application\controllers\user.php on line 84 and exactly 3 expected
Filename: C:\xampp\htdocs\blog\application\models\userregister.php
Line Number: 14
Backtrace:
File: C:\xampp\htdocs\blog\application\controllers\user.php
Line: 84
Function: register1
File: C:\xampp\htdocs\blog\index.php
Line: 315
Function: require_once
please help how to do it
Answer
Solution:
Error message clearly state that your model method required three arguments and you supplied just one.
In your controller
if($this->userregister->register1($post))
change it to
if($this->userregister->register1($post['name'], $post['email'], $post['password']))
I am assuming that $post is an array of $_POST.
Source