Skip to content

Instantly share code, notes, and snippets.

@eslavon
Created February 3, 2019 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eslavon/44bcf6d1f61eb26498588dbc0eea7421 to your computer and use it in GitHub Desktop.
Save eslavon/44bcf6d1f61eb26498588dbc0eea7421 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