Link to home
Start Free TrialLog in
Avatar of dnotestine
dnotestine

asked on

Create a temporary password using given characters

I want to be able to create a password using given characters and length.

i.e.
$Characters = "abcGTH123_%&$";
$Length = 8;

PHP code to do it

Any ideas?
Avatar of codeQuantum
codeQuantum
Flag of Canada image


<?php
 
$pass = "";
$Characters = "abcGTH123_%&$";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 8) {
	$num = rand() % strlen($Characters);
	$tmp = substr($Characters, $num, 1);
	$pass = $pass . $tmp;
	$i++;
}
// see result
echo $pass;
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rob Siklos
Rob Siklos
Flag of Canada image

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
SOLUTION
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
SOLUTION
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 dnotestine
dnotestine

ASKER

Thanks to everyone - All were good examples