added password encryption
This commit is contained in:
parent
790176964d
commit
8ec1a2942d
|
@ -2,22 +2,39 @@
|
||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Controller\ConfigController;
|
||||||
|
use App\Controller\EncryptionController;
|
||||||
|
use Exception;
|
||||||
|
use SodiumException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Apikey
|
class Apikey
|
||||||
{
|
{
|
||||||
private int $id;
|
|
||||||
private string $name;
|
|
||||||
private string $apiTokenPrefix;
|
|
||||||
private string $apiToken;
|
|
||||||
|
|
||||||
public function __construct(string $name, string $apiTokenPrefix, string $apiToken, int $id = 0)
|
public function __construct(
|
||||||
|
private int $id = 0,
|
||||||
|
private string $name = '',
|
||||||
|
private string $apiTokenPrefix = '',
|
||||||
|
private string $apiToken = '',
|
||||||
|
private readonly string $passphrase = ''
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
if ($this->passphrase) {
|
||||||
$this->name = $name;
|
$configController = new ConfigController();
|
||||||
$this->apiTokenPrefix = $apiTokenPrefix;
|
$encryptionController = new EncryptionController();
|
||||||
$this->apiToken = $apiToken;
|
|
||||||
|
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
||||||
|
|
||||||
|
$this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
||||||
|
} catch (Exception|SodiumException $e) {
|
||||||
|
die($e->getMessage() . PHP_EOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue