Codeigniter cannot decode the encrypted password Codeigniter cannot decode the encrypted password codeigniter codeigniter

Codeigniter cannot decode the encrypted password


Please check your codeigniter charset in config

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

versus the charset of your database. Your conflict is probably coming from there.

Put Codeigniter to test and see if it return the right result. Try hard-coding like before or copy and test this in your controller.

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

}

Mine produce the expected result: 12345. If that works, then your problem is possibly CHARACTER SET (CHARSET). I'm using an encryption key here. You could use the default in config by leaving out the second parameter in encode and decode.

Let me know if that helped


You want to hash, rather than encrypt, and you can do this with CodeIgniter's encrypt library which uses SHA1 for hashing.

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

This would return 7c4a8d09ca3762af61e59520943dc26494f8941b, which is what would be stored in the database.

You cannot un hash a password - you want to check the hashed input against the hash in the database.


Have you tried:

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