token generate

This commit is contained in:
2024-10-23 11:38:53 +03:00
parent e3d1722f2c
commit ffa659ea1d
3 changed files with 47 additions and 9 deletions

View File

@ -3,6 +3,7 @@
namespace kernel\services;
use Firebase\JWT\JWT;
use kernel\helpers\Debug;
use Random\RandomException;
class TokenService
@ -22,8 +23,40 @@ class TokenService
*/
public static function random_bytes(int $ln): string
{
$token = random_bytes($ln);
return bin2hex($token);
return bin2hex(random_bytes($ln));
}
/**
* @throws RandomException
*/
public static function md5(): string
{
return md5(microtime() . self::getSalt() . time());
}
/**
* @throws RandomException
*/
public static function crypt(): string
{
return crypt(microtime(), self::getSalt());
}
/**
* @throws RandomException
*/
public static function hash(string $alg): string
{
return hash($alg, self::getSalt());
}
/**
* @throws RandomException
*/
public static function getSalt(): string
{
return bin2hex(random_bytes(10));
}
}