Created
May 4, 2022 12:30
-
-
Save evan4/7cc3faa08acf28b039caa8b7ecbaab3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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