• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using AES_ENCRYPT in model

#1
I am trying CI4 4.0.0-alpha.1 and I encounter something that does not make sense to me. 

I have a user model and want to use AES_ENCRYPT in my sql query.

Solution 1 works, the password is encrypted. Solution 2 doesn't. It stores the password as AES_ENCRYPT('dasdsad','1234')

Is this a bug or is there something I do not understand correctly?

Solution 1 works:

PHP Code:
class UserModel extends \CodeIgniter\Model
{
    protected 
$table 'users';

    public function 
insert_user($data$aes_key)
    {
        
$builder $this->db->table$this->table );

        
$builder->set('user_pwd'"AES_ENCRYPT('{$data['password']}','{$aes_key}')"FALSE);
        
$builder->set('user_name'$data['name'], TRUE);
        
$builder->set('user_email'$data['email'], TRUE);

        
$builder->insert();
    }



Solution 2 doesn't work:

PHP Code:
class UserModel extends \CodeIgniter\Model
{
    protected 
$table 'users';

    public function 
insert_user($data$aes_key)
    {
        
$this->set('user_pwd'"AES_ENCRYPT('{$data['password']}','{$aes_key}')"FALSE);
        
$this->set('user_name'$data['name'], TRUE);
        
$this->set('user_email'$data['email'], TRUE);

        
$this->insert();
    }

Reply


Messages In This Thread
Using AES_ENCRYPT in model - by tvdp - 10-04-2018, 01:07 PM
RE: Using AES_ENCRYPT in model - by Piotr - 10-04-2018, 05:30 PM
RE: Using AES_ENCRYPT in model - by kilishan - 10-04-2018, 07:51 PM
RE: Using AES_ENCRYPT in model - by tvdp - 10-04-2018, 11:05 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.