vendredi 27 août 2021

how to encrypt password with hash sha512 in codeigniter while uploading to db

I want to encrypt my password using hashing when submitting data to the database kindly guide me to where to change the code

Can anyone help me out to find the best encryption method for Codeigniter?

public function register(){ 
    if($this->isUserLoggedIn){ 
          redirect('users/account'); 
         } 
    $data = array(); 
    if($this->session->userdata('success_msg')){ 
        $data['success_msg'] = $this->session->userdata('success_msg'); 
        $this->session->unset_userdata('success_msg'); 
    } 
    if($this->session->userdata('error_msg')){ 
        $data['error_msg'] = $this->session->userdata('error_msg'); 
        $this->session->unset_userdata('error_msg'); 
    } 
    if($this->input->post('signupSubmit')){ 
        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required'); 
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); 
        $this->form_validation->set_rules('mobile_no', 'Mobile', 'required|min_length[10]|max_length[10]|regex_match[/^[0-9]{10}$/]|callback_mobile_no_check'); 
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); 
        $this->form_validation->set_rules('password', 'password', 'required'); 
        $this->form_validation->set_rules('conf_password', 'confirm password', 
'required|matches[password]'); 
 $userData = array( 
            'first_name' => strip_tags($this->input->post('first_name')), 
            'last_name' => strip_tags($this->input->post('last_name')), 
            'email' => strip_tags($this->input->post('email')), 
            'password' => strip_tags($this->input->post('password')), 
            'gender' => $this->input->post('gender'), 
            'mobile_no' => strip_tags($this->input->post('mobile_no')) 
        ); 
            if($this->form_validation->run() == true){ 
            $insert = $this->users_model->insert($userData); 
            if($insert){ 
                $this->session->set_userdata('success_msg', 'Your account registration has been successful. Please login to your account.'); 
                redirect('users/login'); 
            }else{ 
                $data['error_msg'] = 'Some problems occured, please try again.'; 
            } 
        }else{ 
            $data['error_msg'] = 'Please fill all the mandatory fields.'; 
        } 
    }
    // Load view 
    $data['pvalue'] = array('view'=>'login_view','pgTitle'=>'Log In');
    $this->loadView($data);
    
    
}



Aucun commentaire:

Enregistrer un commentaire