Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

php code to javascript - password generator format XXX-XXX-XXX-XXX

can some one please convert this to javascript please

/* Random Password generator.
http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php

We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.

MNC-HU4-GPY-JGD

*/
//len + 1 so 11 = 12 returned
function makeRandomPassword2($len = 11,$upper = 1,$number = 1) {
  $salt = "";
  //$salt = "abcdefghijklmnopqrstuvwxyz";
  $uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $numbers   = "1234567890";
  if ($upper) $salt .= $uppercase;
    if ($number) $salt .= $numbers;
   
srand((double)microtime()*1000000);
$i = 0;
$i1 = 0;
while ($i <= $len) {
  $num = rand() % strlen($salt);
  $tmp = substr($salt, $num, 1);
  $pass = $pass . $tmp;
  $i++;
  $i1++;
  if ($i1 == 3)
  {
  $i1 = 0;
  if ($i >= $len)
  {
  //dont do anything
  }
  else
  {
  $pass = $pass . "-";
  }
 
 
  }
 
 
};
return $pass;
};

thank you in advance for any code and/or help you may provide
ASKER CERTIFIED SOLUTION
Avatar of UnTwstr
UnTwstr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

Thank you