Codeigniter cannot decode encrypted password

I made a registration form in which the user submitted his username and password. If the username exists, I will decrypt the password and check if it matches the password provided.

// This is from db

string(50) "v+bNPHNWHGQbcxrvu1vN8Ty++cMq0oEeaZesvfCfsLgNAFgZno"

// And this is after decoding the line above

string(32) "�� U�U{q�0�4��è€UC��o�/�*�."

But he must return 123456

For coding I use

$this->encrypt->encode('123456');

And this is the secret key

$config['encryption_key'] = 'kRlaMneym7rF';

// Edit

The problem was that the password field was set to varchar 50

+5
source share
5 answers

Please check the codeigniter encoding in config

$config['charset'] = 'UTF-8';

compared to the encoding of your database. Your conflict probably comes from there.

Codeigniter , . , , .

function testencrypting(){
  $str = '12345';
  $key = 'my-secret-key';
  $encrypted = $this->encrypt->encode($str, $key);
  echo $this->encrypt->decode($encrypted, $key);
  exit;

}

Mine : 12345. , , , CHARACTER SET (CHARSET). . , .

,

+4

, , CodeIgniter, SHA1 .

$password = $this->encrypt->sha1('123456');

7c4a8d09ca3762af61e59520943dc26494f8941b, .

- - .

+3

:

$this->encrypt->decode($string);
+2

, . .

+2
source

I get it. I found this to be because the table I used to store the unicode password was latin1. I changed the password of the user table field as utf-8, which seemed to cure this problem

0
source

All Articles