added password encryption
This commit is contained in:
parent
790176964d
commit
8ec1a2942d
|
@ -2,22 +2,39 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Controller\ConfigController;
|
||||
use App\Controller\EncryptionController;
|
||||
use Exception;
|
||||
use SodiumException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
$this->name = $name;
|
||||
$this->apiTokenPrefix = $apiTokenPrefix;
|
||||
$this->apiToken = $apiToken;
|
||||
if ($this->passphrase) {
|
||||
$configController = new ConfigController();
|
||||
$encryptionController = new EncryptionController();
|
||||
|
||||
$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