Re: get hexadecimal hash string for a number
On 9/18/2012 1:08 PM, markspace wrote:
On 9/18/2012 9:25 AM, Magnus Warker wrote:
I want users to register on a site and send confirmation emails to them.
These emails should contain a link like this:
http://myurl?registration=E4AC4BD4
Here, "E4AC4BD4" should be a unique string.
<http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html>
I think UUID is better, as it is more random than just an integer, and
I'm pretty sure it uses a hexadecimal representation, so you can just
use it as-is. Make a new one, call toString, and you're ready to go.
It meets the stated requirements of being unique.
But the original poster most likely have a requirement he
forgot to mention: that it should be hard to guess as well.
The point of emailing a confirmation link is to ensure that the
registrant indeed own the email address.
If the link is guessable then there is no point.
UUID's are not intended to be cryptographic secure, so they
are not the right toll for the job.
The correct approach is to use a cryptographic secure
RNG to generate a number of random bytes.
Being slightly paranoid I will recommend generating
maybe 100 bytes and do a SHA-256 of that just to
protect against weaknesses.
It does not cost much coding or many resources runtime, so
I can not see any reason to not do it the right way.
Arne