Simple password generator

By Deborah - September 19, 2020

Hi, Tim.

I have notes from 2010, but the original forum post is no longer available. I *think* I tried it, but can't be sure.

WAS:
$_REQUEST['password'] = substr(md5(uniqid(rand(), true)), 15);

FOR 4-CHARACTER PASSWORD, CHANGED TO:
$_REQUEST['password'] = substr(md5(uniqid(rand(), true)),0, 4);

Not only was the '15' changed to '4', but the '0,' was also added in front of it.

Hope that works for you.

~ Deborah

By Toledoh - September 19, 2020

Great Deborah, that worked - thanks!

Anyone have any ideas on making it purely numeric?

Cheers,
Tim (toledoh.com.au)

By Carl - September 23, 2020

Hi Toledoh,
You can see that the code snippet Deborah provided has md5 in it, which means the password returned is encrypted. That's what you will want when you're saving the password into the database. If you removed the md5 from the snippet, you would see 4 purely numeric values being returned.

Here's an example of a password being generated without the hash: 1197. 

Carl

PHP Programmer

interactivetools.com

By Toledoh - September 23, 2020

Great - thanks for that Carl!

Cheers,
Tim (toledoh.com.au)