Skip to content

Instantly share code, notes, and snippets.

@nullcookies
Forked from eslavon/func_random_key.php
Created October 17, 2019 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullcookies/61189c7cac4f4f680ef707014843e06f to your computer and use it in GitHub Desktop.
Save nullcookies/61189c7cac4f4f680ef707014843e06f to your computer and use it in GitHub Desktop.
func_random_key
<?php
function keyGenerate($leight) {
if (is_int($leight)) {
$array = array("1", "2", "3", "4", "5", "6", "7", "8", "9","0",
"A","B","D","E","F","G","H","I","J","K","L","M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$count = count($array)-1;
$result = "";
for ($i = 1; $i <= $leight; $i++) {
$random = mt_rand(0,$count);
$case = mt_rand(0,1);
if ($case == 0 ) {
$symbol = mb_strtolower($array[$random]);
} else {
$symbol = $array[$random];
}
$result = $result.$symbol;
}
} else {
$result = "Введите длину генерируемого пароля!";
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment