From 0606c3bea844866085971f193aabdd932f4485cc Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 29 Jun 2026 18:38:15 -0400 Subject: [PATCH] pwd gen --- src/Framework/MoneyFormatter.php | 6 ++++++ src/Framework/Security.php | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Framework/MoneyFormatter.php b/src/Framework/MoneyFormatter.php index 1bb93a7..b0271aa 100644 --- a/src/Framework/MoneyFormatter.php +++ b/src/Framework/MoneyFormatter.php @@ -218,6 +218,12 @@ class MoneyFormatter return $ret; } + public static function isInputDecimalMoney($value) { + $matches = preg_match('/^\s*(?=.*[1-9])\d*(?:\.\d{1,2})?\s*$/', $value); + $decimal = found_string($value, '.'); + return ($matches > 0 && $decimal) ? true : false; + } + public static function getLocaleFromCode(string $currencyCode = "USD", string $locale = "en_US"): ?string { if ($currencyCode === "USD" && $locale === "en_US") { diff --git a/src/Framework/Security.php b/src/Framework/Security.php index d7f7e37..39dfe33 100644 --- a/src/Framework/Security.php +++ b/src/Framework/Security.php @@ -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();