lk-students/app/Helpers/HashHelper.php

30 lines
786 B
PHP
Raw Permalink Normal View History

2024-07-12 12:48:28 +03:00
<?php
namespace App\Helpers;
use App\Models\User;
class HashHelper
{
protected const string algo = 'sha256';
public static function getRecordHash(User $user): string
{
$fields = AllfieldsUserHelper::get();
$data = array_map(fn ($item) => $user->$item, $fields);
$dataInLine = implode($data);
// dd($data);
return hash(self::algo, $dataInLine);
}
public static function getApiHash($infoOfStudent): string
{
// dd($infoOfStudent);
$fields = AllfieldsUserHelper::get();
$data = array_map(fn ($item) => $infoOfStudent[$item], $fields);
// dd($data);
$dataInLine = implode($data);
// dd($dataInLine);
return hash(self::algo, $dataInLine);
}
}