Answer the question
In order to leave comments, you need to log in
How to generate 5 random passwords in php?
Hi all.
There is a password generator:
function generate_password()
{
$arr = array('a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','p','r','s',
't','u','v','x','y','z',
'A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','R','S',
'T','U','V','X','Y','Z',
'1','2','3','4','5','6',
'7','8','9','0','.',',',
'(',')','[',']','!','?',
'&','^','%','@','*','$',
'<','>','/','|','+','-',
'{','}','`','~');
// Генерируем пароль
$pass = "";
for($i = 0; $i < 10; $i++)
{
// Вычисляем случайный индекс массива
$index = rand(0, count($arr) - 1);
$pass .= $arr[$index];
}
return $pass;
}
function generate_password()
{
$arr = array('a','b','c','d','e','f',
'g','h','i','j','k','l',
'm','n','o','p','r','s',
't','u','v','x','y','z',
'A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','R','S',
'T','U','V','X','Y','Z',
'1','2','3','4','5','6',
'7','8','9','0','.',',',
'(',')','[',']','!','?',
'&','^','%','@','*','$',
'<','>','/','|','+','-',
'{','}','`','~');
// Генерируем пароль
$pass = "";
$j = 0;
while ( $j <= 10) {
for($i = 0; $i < 10; $i++)
{
// Вычисляем случайный индекс массива
$index = rand(0, count($arr) - 1);
$pass .= $arr[$index];
$j++;
}
}
return $result = array($pass);
}
print_r(generate_password());
Answer the question
In order to leave comments, you need to log in
and calling the function of generating one password from the cycle is not fate?
$arr=[];
do $arr[]=generate_password(); while (count($arr)<10);
print_r($arr);
Another function, let it take the required number of passwords as a parameter and pull your original function so many times:
function generate_n_passwords($n) {
$result = array();
while($n--) {
array_push( $result, generate_password());
}
return $result;
}
$myFivePasswords = generate_n_passwords(5);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question