added password encryption

This commit is contained in:
tracer 2022-09-22 18:54:54 +02:00
parent 790176964d
commit 8ec1a2942d
1 changed files with 97 additions and 80 deletions

View File

@ -2,89 +2,106 @@
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; public function __construct(
private string $apiTokenPrefix; private int $id = 0,
private string $apiToken; private string $name = '',
private string $apiTokenPrefix = '',
public function __construct(string $name, string $apiTokenPrefix, string $apiToken, int $id = 0) private string $apiToken = '',
{ private readonly string $passphrase = ''
$this->id = $id; )
$this->name = $name; {
$this->apiTokenPrefix = $apiTokenPrefix; if ($this->passphrase) {
$this->apiToken = $apiToken; $configController = new ConfigController();
} $encryptionController = new EncryptionController();
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
/**
* @return String $this->apiTokenPrefix = strtok(string: $this->passphrase, token: '.');
*/
public function getApiToken(): string try {
{ $this->apiToken = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
return $this->apiToken; } catch (Exception|SodiumException $e) {
} die($e->getMessage() . PHP_EOL);
}
/** }
* @return string }
*/
public function getApiTokenPrefix(): string
{ /**
return $this->apiTokenPrefix; * @return String
} */
public function getApiToken(): string
{
/** return $this->apiToken;
* @return int }
*/
public function getId(): int /**
{ * @return string
return $this->id; */
} public function getApiTokenPrefix(): string
{
/** return $this->apiTokenPrefix;
* @param int $id }
*/
public function setId(int $id): void
{ /**
$this->id = $id; * @return int
} */
public function getId(): int
/** {
* @return String return $this->id;
*/ }
public function getName(): string
{ /**
return $this->name; * @param int $id
} */
public function setId(int $id): void
/** {
* @param string $apiTokenPrefix $this->id = $id;
*/ }
public function setApiTokenPrefix(string $apiTokenPrefix): void
{ /**
$this->apiTokenPrefix = $apiTokenPrefix; * @return String
} */
public function getName(): string
/** {
* @param String $apiToken return $this->name;
*/ }
public function setApiToken(string $apiToken): void
{ /**
$this->apiToken = $apiToken; * @param string $apiTokenPrefix
} */
public function setApiTokenPrefix(string $apiTokenPrefix): void
{
/** $this->apiTokenPrefix = $apiTokenPrefix;
* @param String $name }
*/
public function setName(string $name): void /**
{ * @param String $apiToken
$this->name = $name; */
} public function setApiToken(string $apiToken): void
{
$this->apiToken = $apiToken;
}
/**
* @param String $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
} }