Simple password generator

By Toledoh - September 18, 2020

Hi All.

Rather than the long long generated password created automatically via the membership sign-up, I'm wanting a really simple 4 digit code.

How would I change it? I'm guessing something with the following in websiteMembership.php?

function wsm_generatePassword() {
$password = substr(md5(uniqid(mt_rand(), true)), 15); // example output: c5560251ef0b3eef9
return $password;

Tim (

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.

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

$_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?

Tim (

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. 


PHP Programmer