method genpwd documentation in bbn\Str
Returns a random password.
Example
X::dump(\bbn\Str::genpwd());
// (string) "khc9P871w"
X::dump(\bbn\Str::genpwd(6, 4));
// (string) "dDEtxY"
function(int $int_max = NULL, int $int_min = NULL)
{
if (is_null($int_max) && is_null($int_min)) {
$int_max = 12;
$int_min = 8;
}
elseif (is_null($int_min)) {
$int_min = $int_max;
}
elseif (is_null($int_max)) {
$int_max = $int_min;
}
mt_srand();
$len = ($int_min > 0) && ($int_min < $int_max) ? random_int($int_min, $int_max) : $int_max;
$mdp = '';
for($i = 0; $i < $len; $i++){
// First character is a letter
$type = $i === 0 ? random_int(2, 3) : random_int(1, 3);
switch ($type){
case 1:
$mdp .= random_int(0,9);
break;
case 2:
$mdp .= \chr(random_int(65,90));
break;
case 3:
$mdp .= \chr(random_int(97,122));
break;
}
}
return $mdp;
}
Returns a random password. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions