fix tests
This commit is contained in:
@@ -3,33 +3,34 @@
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
if (!function_exists('utc_now')) {
|
||||
if (! function_exists('utc_now')) {
|
||||
function utc_now(): string
|
||||
{
|
||||
return CarbonImmutable::now('UTC')->toDateTimeString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('local_date')) {
|
||||
if (! function_exists('local_date')) {
|
||||
function local_date(string $utcDateTime, string $format = 'Y-m-d H:i:s'): string
|
||||
{
|
||||
try {
|
||||
$carbon = CarbonImmutable::parse($utcDateTime)->setTimezone(config('app.timezone'));
|
||||
|
||||
return $carbon->format($format);
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
return CarbonImmutable::parse($utcDateTime)->format($format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_timezone')) {
|
||||
if (! function_exists('user_timezone')) {
|
||||
function user_timezone(): string
|
||||
{
|
||||
return (string) (config('School')->attendance['timezone'] ?? config('app.timezone', 'America/New_York'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('pbkdf2_hash')) {
|
||||
if (! function_exists('pbkdf2_hash')) {
|
||||
function pbkdf2_hash(string $password, string $algo = 'sha256', int $iterations = 100000, int $length = 64): string
|
||||
{
|
||||
$salt = random_bytes(16);
|
||||
@@ -41,7 +42,7 @@ if (!function_exists('pbkdf2_hash')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('pbkdf2_verify')) {
|
||||
if (! function_exists('pbkdf2_verify')) {
|
||||
function pbkdf2_verify(string $password, string $storedHash): bool
|
||||
{
|
||||
$delim = strpos($storedHash, '$') !== false ? '$' : ':';
|
||||
@@ -62,14 +63,15 @@ if (!function_exists('pbkdf2_verify')) {
|
||||
}
|
||||
|
||||
$calc = hash_pbkdf2($algo, $password, $salt, (int) $iterations, strlen($derived), true);
|
||||
|
||||
return hash_equals($derived, $calc);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('verify_stored_password')) {
|
||||
if (! function_exists('verify_stored_password')) {
|
||||
function verify_stored_password(string $password, ?string $storedHash): bool
|
||||
{
|
||||
if (!$storedHash) {
|
||||
if (! $storedHash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user