|
|
|
|
@ -27,6 +27,32 @@ class Security |
|
|
|
|
use \IOcornerstone\Framework\Trait\Security\CsrfTokenFunctions; |
|
|
|
|
use \IOcornerstone\Framework\Trait\Security\SessionHijackingFunctions; |
|
|
|
|
|
|
|
|
|
public static function generatePassword(int $length = 12): string |
|
|
|
|
{ |
|
|
|
|
$lowercase = 'abcdefghijklmnopqrstuvwxyz'; |
|
|
|
|
$uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
|
|
|
$numbers = '0123456789'; |
|
|
|
|
$symbols = '@_%^()-+'; // $&*!" are INVALID to te shell! |
|
|
|
|
$allCharacters = $lowercase . $uppercase . $numbers . $symbols; |
|
|
|
|
|
|
|
|
|
if ($length < 2) { |
|
|
|
|
$length = 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Build password with required character types |
|
|
|
|
$password = ''; |
|
|
|
|
$password .= $numbers[random_int(0, strlen($numbers) - 1)]; |
|
|
|
|
$password .= $symbols[random_int(0, strlen($symbols) - 1)]; |
|
|
|
|
|
|
|
|
|
// Fill remaining with random characters |
|
|
|
|
for ($i = 2; $i < $length; $i++) { |
|
|
|
|
$password .= $allCharacters[random_int(0, strlen($allCharacters) - 1)]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Shuffle to randomize positions |
|
|
|
|
return str_shuffle($password); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function hexPWD(int $bytes = 16): string |
|
|
|
|
{ |
|
|
|
|
$r = new RandomEngine(); |
|
|
|
|
|