mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-27 21:06:18 +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
|
<?php
|
||||||
/**
|
/**
|
||||||
* Helper functions
|
* This file contains utility functions for Namingo Registry Control Panel.
|
||||||
* @author Hezekiah O. <support@hezecom.com>
|
*
|
||||||
|
* 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;
|
use Pinga\Auth\Auth;
|
||||||
|
@ -17,6 +28,7 @@ use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use libphonenumber\PhoneNumberFormat;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
|
use ZxcvbnPhp\Zxcvbn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed|string|string[]
|
* @return mixed|string|string[]
|
||||||
|
@ -607,3 +619,26 @@ function extractHostTLD(string $hostname): array
|
||||||
|
|
||||||
return ['host' => $host, 'tld' => $tld];
|
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",
|
"egulias/email-validator": "^4.0",
|
||||||
"utopia-php/messaging": "^0.12.0",
|
"utopia-php/messaging": "^0.12.0",
|
||||||
"brick/postcode": "^0.3.3",
|
"brick/postcode": "^0.3.3",
|
||||||
"utopia-php/system": "^0.9.0"
|
"utopia-php/system": "^0.9.0",
|
||||||
|
"bjeavons/zxcvbn-php": "^1.4"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue