• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a short hash

#1
[eluser]dmorin[/eluser]
So here's the deal. I'm creating a site where I send an email and they need to confirm something by clicking a link. But rather then send an MD5 hash as the unique value used to determine that they received the email, I would like to send a shorter random string of maybe 6-8 characters. What's the best way to do this? Should I just calculate an MD5 hash and then grab the first 6 characters and use there, or is there a better way?

I'm aware that by shortening it, my chances for duplicates will be much higher. I'll check the list of existing ones before committing to using one.

If anyone has any ideas of how to better calculate these short hashes/random strings, please let me know. Thanks.

#2
[eluser]Michael Wales[/eluser]
Wow, talk about timing.

About a month ago I wrote an article entitled "Handling Forgotten Passwords" in which I discuss various methods of allowing a user to retrieve/reset a lost password. One of the common themes amongst all of these methods was an emailed verification/activation code - this also happened to be one of the most frequent questions I recieved.

Yesterday I posted an article "Generating Random Strings" which takes a 10-line function I originally suggested (to just generate the random string) to 9-line function, which generates the random string, checks it for duplication, and updates the user's record if it's valid.

Check it out - I'm sure both article will help.

#3
[eluser]dmorin[/eluser]
Perfect, thanks for the response. I didn't know about the random_string() function. That will be a big help.

Thanks again.

#4
[eluser]Jesse Schutt[/eluser]
Michael,

Do you happen to have updated links for those articles?

Jesse

#5
[eluser]Lucas3677[/eluser]
How about substr(md5(microtime()), 0, 6)?

#6
[eluser]Thorpe Obazee[/eluser]
Correct me if I am wrong, but shouldn't uniqid() enough for this?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.