mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-25 20:08:23 +02:00
Added helper functions for password operations
This commit is contained in:
parent
1ca60241a1
commit
841830fbde
2 changed files with 40 additions and 4 deletions
|
@ -1,7 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper functions
|
||||
* @author Hezekiah O. <support@hezecom.com>
|
||||
* 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. <support@hezecom.com>
|
||||
*
|
||||
* @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];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue