Skip to content

Instantly share code, notes, and snippets.

@evan4
Created May 4, 2022 12:30
Show Gist options
  • Save evan4/7cc3faa08acf28b039caa8b7ecbaab3e to your computer and use it in GitHub Desktop.
Save evan4/7cc3faa08acf28b039caa8b7ecbaab3e to your computer and use it in GitHub Desktop.
<?php
function password_renerate(int $chars, int $res_ammount)
{
if ($chars === 0) {
throw new \RangeException("Длина пароля должна быть больше 0");
}
if ($res_ammount === 0) {
throw new \RangeException("Количество результатов должно быть больше 0");
}
$symbols = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$symbols_length = strlen($symbols) - 1;
$passwords_array = [];
for ($i=0; $i < $res_ammount; $i++) {
$pass = '';
for ($j=0; $j < $chars; $j++) {
$pass .= $symbols[random_int(0, $symbols_length)];
}
array_push($passwords_array, $pass);
}
return $passwords_array;
}
$pass = password_renerate(15, 2);
print_r($pass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment