<?php
namespace Slivki\Services;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
class Encoder implements PasswordEncoderInterface
{
public static function encodeString($raw, $salt)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $raw, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
public static function decodeString($cipher, $salt)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($cipher), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
public function encodePassword(string $raw, ?string $salt)
{
return self::encodeString($raw, $salt);
}
public function isPasswordValid(string $encoded, string $raw, ?string $salt)
{
return $encoded == self::encodePassword($raw, $salt);
}
public function needsRehash(string $encoded): bool
{
return false;
}
}