PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php print_r(generatePassword(4,8)); function generatePassword(int $lvl, int $lenght) { if($lvl < 1 || $lvl > 4){ throw new InvalidArgumentException("Level not between 1 and 4"); } $lowercase = "abcdefghijkimnopqrstuvwxyz"; $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); $strlenght = strlen($shufflePool); $password = ""; for($i = 0; $i < $lenght;$i++){ $password .= $shufflePool[random_int(0,$strlenght- 1 )]; } return $password; }
Show:  
Copy Clear