0

I am using a script in wich I need to create a unique Hash with jQuery that I would be able similar to the PHP function uniqid().

Any help ?

Art Planteur
  • 523
  • 2
  • 8
  • 18
  • what do you mean "reproduce"? if you can reproduce it, it's not unique. you mean you want something in a similar format? – mpen Mar 04 '13 at 22:41
  • downvote: What have you tried? Google for `javascript random generator` and enjoy – Green Black Mar 04 '13 at 22:43
  • Are you talking about the location.hash, which you don't have access to on the serverside? You're probably talking about password hashing, and the point of hashing is that it can't be reproduced, so what you need is some sort of encryption wich will work in both languages, and nothing like that is readily available, but there are plugins and more advanced solutions that will do that. – adeneo Mar 04 '13 at 22:43
  • The point of hashing is that it CAN be reproduced...... if you have the same input. And md5 / sha / others, take your pick. – Wrikken Mar 04 '13 at 22:45
  • 1
    If you are about javascript uuid generation, try this http://stackoverflow.com/a/105074/2124762 – Mailk Gunputh Mar 04 '13 at 22:46
  • Thanks mailk, i want to reproduce uniqId – Art Planteur Mar 04 '13 at 22:46

2 Answers2

4

What I think you need is the jquery md5 plugin that will create an md5 hash of a string which should shell out a unique hash for any string you give it. check out https://github.com/placemarker/jQuery-MD5

and then check out http://php.net/manual/en/function.md5.php for the php function to do the same

DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
1

The uniqid function in php is using the current time in milliseconds. It is not possible to generate the same hash on the client, as timing will be different.

Piddien
  • 1,436
  • 4
  • 18
  • 38