0

I have:

$token  = sha1(uniqid(mt_rand(), true));

Then I'll insert it into the database using unhex('$token'). How do I select this value?

I've tried:

SELECT token FROM `name` WHERE `id` = 1 LIMIT 1

If I echo it in it'll show as 0b7GÞ÷:‹xcÅ•½JAjdäáæ rather than something like 5dc012f007b7c4db7b9e076138fdd92fa1039530

What am I doing wrong?

ditto
  • 5,917
  • 10
  • 51
  • 88
  • _"What am I doing wrong?"_ - how about: you are using UNHEX in the first place? I mean, what for do you do that? And if you really think this is necessary - why haven't you read in the manual about what the "inverse" function to UNHEX is? – CBroe Mar 17 '13 at 00:36
  • @CBroe http://stackoverflow.com/questions/614476/storing-sha1-hash-values-in-mysql – ditto Mar 17 '13 at 00:39

1 Answers1

1

I don't think you need to store it with UNHEX, but you can SELECT HEX(token) to get back the original value.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • I figured out moments ago I had to do "HEX(token) as token", leaving out the as token was causing an undefined index error. Thanks. :) – ditto Mar 17 '13 at 00:37