30 lines
491 B
PHP
30 lines
491 B
PHP
<?php
|
|
namespace Core;
|
|
|
|
use Defuse\Crypto\Key;
|
|
|
|
class Hash
|
|
{
|
|
public static function make($string, $salt = '')
|
|
{
|
|
return crypt($string, $salt);
|
|
}
|
|
|
|
public static function salt()
|
|
{
|
|
$salt = Key::createNewRandomKey();
|
|
$salt = $salt->saveToAsciiSafeString();
|
|
return $salt;
|
|
}
|
|
|
|
public static function unique()
|
|
{
|
|
return self::make(uniqid());
|
|
}
|
|
|
|
public static function compare($string, $salt, $hash)
|
|
{
|
|
return hash_equals($hash, Hash::make($string, $salt));
|
|
}
|
|
}
|