diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index 1d8649b..2c6ae89 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -1,7 +1,18 @@ + * This file contains utility functions for Namingo Registry Control Panel. + * + * Written and maintained by: + * - Taras Kondratyuk (2023-2025) + * + * This file also incorporates functions: + * - Hezekiah O. + * + * @package Namingo Panel + * @author Taras Kondratyuk + * @copyright 2023-2025 Namingo + * @license MIT License + * @version 1.0 */ use Pinga\Auth\Auth; @@ -17,6 +28,7 @@ use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use libphonenumber\PhoneNumberUtil; use libphonenumber\PhoneNumberFormat; use libphonenumber\NumberParseException; +use ZxcvbnPhp\Zxcvbn; /** * @return mixed|string|string[] @@ -606,4 +618,27 @@ function extractHostTLD(string $hostname): array $host = array_pop($parts); // Get the second last part as host return ['host' => $host, 'tld' => $tld]; -} \ No newline at end of file +} + +function checkPasswordComplexity($password) { + $zxcvbn = new Zxcvbn(); + + // Use configured or default password strength requirement + $requiredScore = getenv('PASSWORD_STRENGTH') ?: 3; // Default to score 3 if ENV is not set + + $score = $zxcvbn->passwordStrength($password)['score']; + + if ($score < $requiredScore) { // Score ranges from 0 (weak) to 4 (strong) + throw new Exception('Password too weak. Use a stronger password.'); + } +} + +function checkPasswordRenewal($lastPasswordUpdateTimestamp) { + // Use configured or default password expiration days + $passwordExpiryDays = getenv('PASSWORD_EXPIRATION_DAYS') ?: 90; // Default to 90 days + + if (time() - $lastPasswordUpdateTimestamp > $passwordExpiryDays * 86400) { + return 'Your password is expired. Please change it.'; + } + return null; +} diff --git a/cp/composer.json b/cp/composer.json index 986a172..7662728 100644 --- a/cp/composer.json +++ b/cp/composer.json @@ -46,7 +46,8 @@ "egulias/email-validator": "^4.0", "utopia-php/messaging": "^0.12.0", "brick/postcode": "^0.3.3", - "utopia-php/system": "^0.9.0" + "utopia-php/system": "^0.9.0", + "bjeavons/zxcvbn-php": "^1.4" }, "autoload": { "psr-4": {