Johnny
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 = "abcdefghijklmnopqrstuvwxy z";
$uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXY Z";
$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
/* 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 = "abcdefghijklmnopqrstuvwxy
$uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXY
$numbers = "1234567890";
if ($upper) $salt .= $uppercase;
if ($number) $salt .= $numbers;
srand((double)microtime()*
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER