CodeIgniter Forums
Why does encode() return a different value each time? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why does encode() return a different value each time? (/showthread.php?tid=56172)



Why does encode() return a different value each time? - El Forum - 11-30-2012

[eluser]lanzd[/eluser]
Normally when I storing passwords I md5() them because I normally don't intend on ever retrieving them, only resetting them if anything.

I am new to CI and tried out
Code:
$this->encrypt->encode('testPassword');

It seems to generate a different result each time I load the page. I understood the CI documentation as using whatever value I set as my encryption key in my config.php file as a salt and worked from there.

Shouldn't that produce the same result? or does the encode use a timestamp or something in addition to that?

I know I can just you md5() which I am currently still using, but I was curious about this behavior.

Thanks, Dan




Why does encode() return a different value each time? - El Forum - 12-01-2012

[eluser]Aken[/eluser]
Open up the Encryption library and look. All the code is right there.


Why does encode() return a different value each time? - El Forum - 12-05-2012

[eluser]lanzd[/eluser]
Ahh, thank you. Silly me, I forgot I can view/edit the built in libraries to my hearts content.

In the encrypt library for the encode() function It reads:

Code:
/**
  * Encode
  *
  * Encodes the message string using bitwise XOR encoding.
  * The key is combined with a random hash, and then it
  * too gets converted using XOR. The whole thing is then run
  * through mcrypt (if supported) using the randomized key.
  * The end result is a double-encrypted message string
  * that is randomized with each call to this function,
  * even if the supplied message and key are the same.
  *
  * @access public
  * @param string the string to encode
  * @param string the key
  * @return string
  */

I was about to ask what is the purpose of this if you cannot undo the process, but found the decode() function in the library as well.

Thank you for your help, and sorry for the simple question.

Dan