PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Wed Feb 02, 2005 7:55 am
how can i create random string of md5?
for example like the ones inthe adress bar of this forum
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Feb 02, 2005 12:26 pm
Look at the first comment on the PHP manual page for rand(). That gives a good random string. If you want, you can then MD5 that string.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Feb 02, 2005 1:50 pm
Surely the whole point of MD5 is that its not random..
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Wed Feb 02, 2005 2:08 pm
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Wed Feb 02, 2005 2:29 pm
If your just looking for a "random" hash try this:
Code: Select all
$str = md5(time());
or
$str = md5(microtime());
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Wed Feb 02, 2005 7:50 pm
what's the point of hashing it if its just random? it seems like a waste of resources.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Wed Feb 02, 2005 8:49 pm
I've done stuff like this before; for example if you need a random 12 dig alphanumeric key for something. I've used:
If there is a better way to do this I'd like to know.....
pelegk2
Forum Regular
Posts: 633 Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:
Post
by pelegk2 » Thu Feb 03, 2005 1:33 am
all of you for all ofyour idea's