feat: encrypted user passwords

This commit is contained in:
Björn Fromme
2025-04-24 12:26:42 +02:00
parent 5fe88fc0f2
commit fb6665668b
16 changed files with 292 additions and 79 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Security;
use Spatie\Crypto\Rsa\PrivateKey;
use Spatie\Crypto\Rsa\PublicKey;
class Crypt
{
public function __construct(private readonly string $path)
{
}
public function encrypt(string $message): string
{
$privateKey = PrivateKey::fromFile($this->path . '/private.key');
return $privateKey->encrypt($message);
}
public function decrypt(string $message): string
{
$publicKey = PublicKey::fromFile($this->path . '/public.key');
return $publicKey->decrypt($message);
}
public function sign(string $message): string
{
$privateKey = PrivateKey::fromFile($this->path . '/private.key');
return $privateKey->sign($message);
}
public function verify(string $message, string $signature): bool
{
$publicKey = PublicKey::fromFile($this->path . '/public.key');
return $publicKey->verify($message, $signature);
}
}
+4 -7
View File
@@ -3,7 +3,7 @@
namespace App\Security\Voter;
use App\BusProNet\Model\Booking;
use Symfony\Component\HttpFoundation\RequestStack;
use App\BusProNet\Security\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
@@ -12,10 +12,6 @@ class BookingVoter extends Voter
public const VIEW = 'VIEW';
public const EDIT = 'EDIT';
public function __construct(private readonly RequestStack $requestStack)
{
}
protected function supports(string $attribute, mixed $subject): bool
{
if (false === in_array($attribute, [self::VIEW, self::EDIT])) {
@@ -27,7 +23,8 @@ class BookingVoter extends Voter
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$bpnUser = $this->requestStack->getSession()->get('bpn_user');
/** @var User $bpnUser */
$bpnUser = $token->getUser();
if (null === $bpnUser) {
return false;
@@ -42,4 +39,4 @@ class BookingVoter extends Voter
return $booking->isEditable();
}
}
}