PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php print_r(generatePassword(3,8)); function generatePassword(int $lvl, int $lenght) { if ($lvl <1 || $lvl >4){ throw new InvalidArumentExecption('Level not between 1 and 4'); } $lovercase = "abcdefghijklmnopqprstuvwxyz"; $uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $numbers = "0123456789"; $specialChars = "+!@.&[]{}|"; $charpool = $lowercase; if ($lvl >=2){ $charPool.=$uppercase; } if ($lvl >=3){ $charPool.=$numbers; } if ($lvl >=4){ $charPool.=$specialChars; } $shufflePool = str_shuffle($charPool); $password = ''; $strLenght = strlen($shufflePool); for($i = 0; $i < $lenght;$i++){ $password .= $shufflePool[random_int(0,$strLenght-1)]; } return $password; }
Show:  
Copy Clear